Skip to content

Commit

Permalink
docs: updated changelog and readme
Browse files Browse the repository at this point in the history
  • Loading branch information
schaechinger committed Aug 23, 2021
1 parent 3d6d750 commit ee05b95
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 12 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.9.0] - Unreleased
## [0.9.0] - 2021-08-23

### Added

Expand Down
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ A node implementation to use the Internetmarke web service of Deutsche Post.
- [Product List](#product-list)
- [Oudated Products](#outdated-products)
- [Catalog List](#catalog-list)
- [Match Product for Letter](#match-product-for-letter)

## Installation

Expand Down Expand Up @@ -474,6 +475,27 @@ const catalogs = await internetmarke.getCatalogList();
const catalog = await internetmarke.getCatalog('Entgeltzone');
```

### Match Product for Letter

Your letter is complete are the only thing left is the voucher. But which one is
neccessary for the letter? The `matchProduct()` method calculates the right one
for you. Depending on your needs and the combination of paper end envelope the
corrept product is retrieved.

```typescript
const options: MatchProductOptions = {
pages: 1, // the number of pages
paper, // optional, defines the paper format and grammage that is used for the letter, defaults to DIN A4 with 80 g/m²
envelope, // optional, defines the envelope format and grammage that is used for the letter, defaults to DIN Lang with 90 g/m²
domestic, // optional, whether the letter is sent within Germany, defaults to true
priority, // optional, whether the letter should be sent as priority letter, defaults to false
registered, // optional, 'Einschreiben'; whether the letter should as registered letter letter, defaults to false
tracking // optional, whether the letter should trackable, defaults to false
};

const product = await internetmarke.matchProduct(options);
```

[npm-url]: https://npmjs.org/package/internetmarke
[npm-svg]: https://img.shields.io/npm/v/internetmarke.svg
[npm-downloads-svg]: https://img.shields.io/npm/dm/internetmarke.svg
Expand Down
5 changes: 2 additions & 3 deletions src/prodWs/product.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export interface Product {
}

export interface MatchProductOptions {
paperCount: number;
pages: number;
paper?:
| {
// defaults to 'A4'
Expand Down Expand Up @@ -218,8 +218,7 @@ export const matchProduct = (products: Product[], options: MatchProductOptions):
}
const envelopeDetails = getPaperDetails(matchOptions.envelope!.format, envelopeOptions);

const weight =
paperDetails.weight.value * options.paperCount + (envelopeDetails?.weight.value || 0);
const weight = paperDetails.weight.value * options.pages + (envelopeDetails?.weight.value || 0);
const dimensions = envelopeDetails?.dimensions || paperDetails.dimensions;

const validProducts = products.filter(product => {
Expand Down
3 changes: 3 additions & 0 deletions test/Internetmarke.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ describe('Internetmarke', () => {
expect(internetmarke.getCatalog('name')).to.eventually.be.rejectedWith(InternetmarkeError),
expect(internetmarke.getProductList()).to.eventually.be.rejectedWith(InternetmarkeError),
expect(internetmarke.getProduct(0)).to.eventually.be.rejectedWith(InternetmarkeError),
expect(internetmarke.matchProduct({ pages: 1 })).to.eventually.be.rejectedWith(
InternetmarkeError
),

expect(internetmarke.initProductService({} as any)).to.eventually.be.rejected
]);
Expand Down
16 changes: 8 additions & 8 deletions test/prodWs/product/product.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,36 +21,36 @@ describe('Product', () => {

describe('matchProduct', () => {
it('should match a product for a single DIN A4 paper in DIN Lang envelope', () => {
const product = matchProduct(productList, { paperCount: 1 })!;
const product = matchProduct(productList, { pages: 1 })!;

expect(product).to.exist;
expect(product.id).to.equal(1);
});

it('should match a product for five DIN A4 papers in DIN Lang envelope', () => {
const product = matchProduct(productList, { paperCount: 5 })!;
const product = matchProduct(productList, { pages: 5 })!;

expect(product).to.exist;
expect(product.id).to.equal(11);
});

it('should match a product for five DIN A5 papers in DIN Lang envelope', () => {
const product = matchProduct(productList, { paperCount: 5, paper: DinPaper.DinA5 })!;
const product = matchProduct(productList, { pages: 5, paper: DinPaper.DinA5 })!;

expect(product).to.exist;
expect(product.id).to.equal(1);
});

it('should match a product for a single DIN A4 paper in DIN C4 envelope', () => {
const product = matchProduct(productList, { paperCount: 5, envelope: DinEnvelope.DinC4 })!;
const product = matchProduct(productList, { pages: 5, envelope: DinEnvelope.DinC4 })!;

expect(product).to.exist;
expect(product.id).to.equal(21);
});

xit('should match a product for post cards', () => {
const product = matchProduct(productList, {
paperCount: 1,
pages: 1,
paper: { format: DinPaper.DinA6, grammage: 150 },
envelope: DinEnvelope.None
})!;
Expand All @@ -60,21 +60,21 @@ describe('Product', () => {
});

it('should match a product with priority label', () => {
const product = matchProduct(productList, { paperCount: 1, priority: true })!;
const product = matchProduct(productList, { pages: 1, priority: true })!;

expect(product).to.exist;
expect(product.id).to.equal(195);
});

it('should match a product with registered label', () => {
const product = matchProduct(productList, { paperCount: 1, registered: true })!;
const product = matchProduct(productList, { pages: 1, registered: true })!;

expect(product).to.exist;
expect(product.id).to.equal(1002);
});

it('should match a product for an abroad letter', () => {
const product = matchProduct(productList, { paperCount: 1, domestic: false })!;
const product = matchProduct(productList, { pages: 1, domestic: false })!;

expect(product).to.exist;
expect(product.id).to.equal(10001);
Expand Down

0 comments on commit ee05b95

Please sign in to comment.