From b35a9065522ada373fdafda56dc5f36c72edcb8e Mon Sep 17 00:00:00 2001 From: Manuel Schaechinger Date: Fri, 20 Aug 2021 14:50:26 +0200 Subject: [PATCH] fix: update user wallet balance if a zero euros --- CHANGELOG.md | 10 ++++++++++ SECURITY.md | 1 + package.json | 4 ++-- src/User.ts | 2 +- src/portokasse/Service.ts | 2 +- test/User.spec.ts | 16 ++++++++++++++++ 6 files changed, 31 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ee615d2..edff208 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,16 @@ 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.8.0] - 2021-08-20 + +### Added + +- Shopping cart matches product with receiver address to avoid wrong vouchers + +### Fixed + +- User did not set wallet balance if it was empty with zero Euros + ## [0.7.1] - 2021-08-20 ### Fixed diff --git a/SECURITY.md b/SECURITY.md index ad7bccd..744c843 100644 --- a/SECURITY.md +++ b/SECURITY.md @@ -8,6 +8,7 @@ Until then only the latest 0.x minor release is supported. | Version | Supported | | ------- | ------------------ | +| 0.8.x | :white_check_mark: | | 0.7.x | :white_check_mark: | | < 0.7 | :x: | diff --git a/package.json b/package.json index 0bd7f92..1a480c8 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "internetmarke", - "version": "0.7.1", + "version": "0.8.0", "description": "A node implementation to use the Internetmarke web service of Deutsche Post.", "keywords": [ "internetmarke", @@ -31,7 +31,7 @@ "test": "mocha -r ts-node/register 'test/**/*.spec.ts'", "test:dot": "npm run test -- -R dot", "test:codecov": "nyc --reporter=cobertura npm run test", - "test:coverage": "nyc npm run test" + "test:coverage": "nyc npm run test:dot" }, "engines": { "node": ">=10.0.0" diff --git a/src/User.ts b/src/User.ts index 15a3d42..d763cec 100644 --- a/src/User.ts +++ b/src/User.ts @@ -78,7 +78,7 @@ export class User { return; } - if (data.walletBalance) { + if (undefined !== data.walletBalance) { this.walletBalance = parseAmount(data.walletBalance); } if (undefined !== data.showTermsAndCondition) { diff --git a/src/portokasse/Service.ts b/src/portokasse/Service.ts index 531701f..b04f5a0 100644 --- a/src/portokasse/Service.ts +++ b/src/portokasse/Service.ts @@ -87,7 +87,7 @@ export class PortokasseService extends RestService implements Portokasse { const res = await this.request('GET', '/api/v1/wallet-overviews/me'); - if (res?.balance) { + if (!Number.isNaN(res?.balance)) { this.user.load({ walletBalance: res.balance }); diff --git a/test/User.spec.ts b/test/User.spec.ts index 947ccbf..409fc5f 100644 --- a/test/User.spec.ts +++ b/test/User.spec.ts @@ -46,6 +46,22 @@ describe('User', () => { expect(info.orderIds).to.be.empty; }); + it('should load user data with 0 balance', () => { + const emptydata: UserData = { + walletBalance: 0, + infoMessage: 'msg', + showTermsAndCondition: true, + userToken: '' + }; + user.load(emptydata); + + const info = user.getInfo(); + + expect(info).to.exist; + expect(info.walletBalance).to.exist; + expect(info.walletBalance!.value).to.equal(0); + }); + it('should not load data without a valid token', () => { const infoUpdate = { walletBalance: 2000