Skip to content

Commit

Permalink
refactor: add ESLint for tests
Browse files Browse the repository at this point in the history
  • Loading branch information
HormCodes committed Jan 5, 2022
1 parent 13f7f64 commit 98fb3d6
Show file tree
Hide file tree
Showing 6 changed files with 156 additions and 50 deletions.
6 changes: 6 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = {
plugins: ['jest'],
rules: {
'jest/no-focused-tests': 'error',
},
};
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"dev": "tsc --watch",
"build": "tsc",
"test": "tsdx test",
"lint": "tsdx lint src",
"lint": "tsdx lint src test",
"lint-fix": "tsdx lint src --fix",
"release": "standard-version"
},
Expand Down Expand Up @@ -75,6 +75,7 @@
"@semantic-release/npm": "^7.1.3",
"@semantic-release/release-notes-generator": "^9.0.3",
"dotenv": "8.2.0",
"eslint-plugin-jest": "^25.3.4",
"husky": "^4.3.0",
"nock": "^13.2.1",
"standard-version": "^9.0.0",
Expand Down
85 changes: 44 additions & 41 deletions test/checkout.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,40 +7,41 @@ const username = process.env.KLARNA_USERNAME;
const password = process.env.KLARNA_PASSWORD;

describe('checkout v3', () => {

let klarna: IKlarnaInstance;
let orderId: string;

beforeAll((done) => {
beforeAll(done => {
if (username && password) {
klarna = new Klarna({ username, password });
done();
}
});
it('should create an order', async () => {

it('should create an order', async () => {
const dummyOrderObj = {
purchase_country: 'NO',
purchase_currency: 'NOK',
locale: 'nb-NO',
order_amount: 50000,
order_tax_amount: 4545,
order_lines: [{
type: "physical",
reference: "19-402-NO",
name: "Random product",
quantity: 5,
unit_price: 10000,
tax_rate: 1000,
total_amount: 50000,
total_tax_amount: 4545,
}],
order_lines: [
{
type: 'physical',
reference: '19-402-NO',
name: 'Random product',
quantity: 5,
unit_price: 10000,
tax_rate: 1000,
total_amount: 50000,
total_tax_amount: 4545,
},
],
merchant_urls: {
checkout: "https://www.example.com/terms.html",
confirmation: "https://www.example.com/confirmation",
push: "https://www.example.com/confirmation",
terms: "https://www.example.com/terms"
}
checkout: 'https://www.example.com/terms.html',
confirmation: 'https://www.example.com/confirmation',
push: 'https://www.example.com/confirmation',
terms: 'https://www.example.com/terms',
},
};

const dummyOrder = await klarna.checkoutV3.createOrder(dummyOrderObj);
Expand All @@ -50,40 +51,42 @@ describe('checkout v3', () => {
expect(dummyOrder).toHaveProperty('statusCode', 201);
});


it('should retrieve an order', async () => {
const order = await klarna.checkoutV3.retrieveOrder(orderId);
expect(order).toHaveProperty('statusCode', 200);
const order = await klarna.checkoutV3.retrieveOrder(orderId);
expect(order).toHaveProperty('statusCode', 200);
});

it('should update an order', async () => {

const dummyUpdateOrderObj = {
purchase_country: 'NO',
purchase_currency: 'NOK',
locale: 'nb-NO',
order_amount: 50000,
order_tax_amount: 4545,
order_lines: [{
type: "physical",
reference: "19-402-NO-update", // changed reference
name: "Random product",
quantity: 5,
unit_price: 10000,
tax_rate: 1000,
total_amount: 50000,
total_tax_amount: 4545,
}],
order_lines: [
{
type: 'physical',
reference: '19-402-NO-update', // changed reference
name: 'Random product',
quantity: 5,
unit_price: 10000,
tax_rate: 1000,
total_amount: 50000,
total_tax_amount: 4545,
},
],
merchant_urls: {
checkout: "https://www.example.com/terms.html",
confirmation: "https://www.example.com/confirmation",
push: "https://www.example.com/confirmation",
terms: "https://www.example.com/terms"
}
checkout: 'https://www.example.com/terms.html',
confirmation: 'https://www.example.com/confirmation',
push: 'https://www.example.com/confirmation',
terms: 'https://www.example.com/terms',
},
};

const order = await klarna.checkoutV3.updateOrder(orderId, dummyUpdateOrderObj);
const order = await klarna.checkoutV3.updateOrder(
orderId,
dummyUpdateOrderObj
);
expect(order).toHaveProperty('statusCode', 200);
});

});
});
8 changes: 4 additions & 4 deletions test/crystallize-helpers.spec.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { CrystallizeKlarnaHelpers } from "../src";
import { CrystallizeKlarnaHelpers } from '../src';

describe('initiate crystallize klarna helpers library', () => {
it('library should have getOrderBody property', async () => {
const crystallizeKlarnaHelpers = new CrystallizeKlarnaHelpers({
host_uri: 'http://localhost:3000'
host_uri: 'http://localhost:3000',
});

expect(crystallizeKlarnaHelpers).toHaveProperty('getOrderBody');
});
});
});
4 changes: 2 additions & 2 deletions test/init.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ describe('initiate library', () => {
username: 'username',
password: 'password',
});

expect(klarna).toHaveProperty('checkoutV3');
});
});
});
100 changes: 98 additions & 2 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1575,6 +1575,11 @@
resolved "https://registry.yarnpkg.com/@types/json-schema/-/json-schema-7.0.6.tgz#f4c7ec43e81b319a9815115031709f26987891f0"
integrity sha512-3c+yGKvVP5Y9TYBEibGNR+kLtijnj7mYrXRg+WpFb2X9xm04g/DXYkfg4hmzJQosc9snFNUPkbYIhu+KAm6jJw==

"@types/json-schema@^7.0.9":
version "7.0.9"
resolved "https://registry.yarnpkg.com/@types/json-schema/-/json-schema-7.0.9.tgz#97edc9037ea0c38585320b28964dde3b39e4660d"
integrity sha512-qcUXuemtEu+E5wZSJHNxUXeCZhAfXKQ41D+duX+VYPde7xyEVZci+/oXKJL13tnRs9lR2pr4fod59GT6/X1/yQ==

"@types/json5@^0.0.29":
version "0.0.29"
resolved "https://registry.yarnpkg.com/@types/json5/-/json5-0.0.29.tgz#ee28707ae94e11d2b827bcbe5270bcea7f3e71ee"
Expand Down Expand Up @@ -1644,6 +1649,18 @@
eslint-scope "^5.0.0"
eslint-utils "^2.0.0"

"@typescript-eslint/experimental-utils@^5.0.0":
version "5.9.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/experimental-utils/-/experimental-utils-5.9.0.tgz#652762d37d6565ef07af285021b8347b6c79a827"
integrity sha512-ZnLVjBrf26dn7ElyaSKa6uDhqwvAi4jBBmHK1VxuFGPRAxhdi18ubQYSGA7SRiFiES3q9JiBOBHEBStOFkwD2g==
dependencies:
"@types/json-schema" "^7.0.9"
"@typescript-eslint/scope-manager" "5.9.0"
"@typescript-eslint/types" "5.9.0"
"@typescript-eslint/typescript-estree" "5.9.0"
eslint-scope "^5.1.1"
eslint-utils "^3.0.0"

"@typescript-eslint/parser@^2.12.0":
version "2.34.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/parser/-/parser-2.34.0.tgz#50252630ca319685420e9a39ca05fe185a256bc8"
Expand All @@ -1654,6 +1671,19 @@
"@typescript-eslint/typescript-estree" "2.34.0"
eslint-visitor-keys "^1.1.0"

"@typescript-eslint/scope-manager@5.9.0":
version "5.9.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/scope-manager/-/scope-manager-5.9.0.tgz#02dfef920290c1dcd7b1999455a3eaae7a1a3117"
integrity sha512-DKtdIL49Qxk2a8icF6whRk7uThuVz4A6TCXfjdJSwOsf+9ree7vgQWcx0KOyCdk0i9ETX666p4aMhrRhxhUkyg==
dependencies:
"@typescript-eslint/types" "5.9.0"
"@typescript-eslint/visitor-keys" "5.9.0"

"@typescript-eslint/types@5.9.0":
version "5.9.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/types/-/types-5.9.0.tgz#e5619803e39d24a03b3369506df196355736e1a3"
integrity sha512-mWp6/b56Umo1rwyGCk8fPIzb9Migo8YOniBGPAQDNC6C52SeyNGN4gsVwQTAR+RS2L5xyajON4hOLwAGwPtUwg==

"@typescript-eslint/typescript-estree@2.34.0":
version "2.34.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/typescript-estree/-/typescript-estree-2.34.0.tgz#14aeb6353b39ef0732cc7f1b8285294937cf37d5"
Expand All @@ -1667,6 +1697,27 @@
semver "^7.3.2"
tsutils "^3.17.1"

"@typescript-eslint/typescript-estree@5.9.0":
version "5.9.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/typescript-estree/-/typescript-estree-5.9.0.tgz#0e5c6f03f982931abbfbc3c1b9df5fbf92a3490f"
integrity sha512-kxo3xL2mB7XmiVZcECbaDwYCt3qFXz99tBSuVJR4L/sR7CJ+UNAPrYILILktGj1ppfZ/jNt/cWYbziJUlHl1Pw==
dependencies:
"@typescript-eslint/types" "5.9.0"
"@typescript-eslint/visitor-keys" "5.9.0"
debug "^4.3.2"
globby "^11.0.4"
is-glob "^4.0.3"
semver "^7.3.5"
tsutils "^3.21.0"

"@typescript-eslint/visitor-keys@5.9.0":
version "5.9.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/visitor-keys/-/visitor-keys-5.9.0.tgz#7585677732365e9d27f1878150fab3922784a1a6"
integrity sha512-6zq0mb7LV0ThExKlecvpfepiB+XEtFv/bzx7/jKSgyXTFD7qjmSu1FoiS0x3OZaiS+UIXpH2vd9O89f02RCtgw==
dependencies:
"@typescript-eslint/types" "5.9.0"
eslint-visitor-keys "^3.0.0"

JSONStream@^1.0.4:
version "1.3.5"
resolved "https://registry.yarnpkg.com/JSONStream/-/JSONStream-1.3.5.tgz#3208c1f08d3a4d99261ab64f92302bc15e111ca0"
Expand Down Expand Up @@ -3028,6 +3079,13 @@ debug@^4.0.0, debug@^4.0.1, debug@^4.1.0, debug@^4.1.1:
dependencies:
ms "^2.1.1"

debug@^4.3.2:
version "4.3.3"
resolved "https://registry.yarnpkg.com/debug/-/debug-4.3.3.tgz#04266e0b70a98d4462e6e288e38259213332b664"
integrity sha512-/zxw5+vh1Tfv+4Qn7a5nsbcJKPaSvCDhojn6FEl9vupwK2VCSDtEiEtqr8DFtzYFOdz63LBkxec7DYuc2jon6Q==
dependencies:
ms "2.1.2"

debuglog@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/debuglog/-/debuglog-1.0.1.tgz#aa24ffb9ac3df9a2351837cfb2d279360cd78492"
Expand Down Expand Up @@ -3408,6 +3466,13 @@ eslint-plugin-import@^2.18.2:
resolve "^1.17.0"
tsconfig-paths "^3.9.0"

eslint-plugin-jest@^25.3.4:
version "25.3.4"
resolved "https://registry.yarnpkg.com/eslint-plugin-jest/-/eslint-plugin-jest-25.3.4.tgz#2031dfe495be1463330f8b80096ddc91f8e6387f"
integrity sha512-CCnwG71wvabmwq/qkz0HWIqBHQxw6pXB1uqt24dxqJ9WB34pVg49bL1sjXphlJHgTMWGhBjN1PicdyxDxrfP5A==
dependencies:
"@typescript-eslint/experimental-utils" "^5.0.0"

eslint-plugin-jsx-a11y@^6.2.3:
version "6.3.1"
resolved "https://registry.yarnpkg.com/eslint-plugin-jsx-a11y/-/eslint-plugin-jsx-a11y-6.3.1.tgz#99ef7e97f567cc6a5b8dd5ab95a94a67058a2660"
Expand Down Expand Up @@ -3454,7 +3519,7 @@ eslint-plugin-react@^7.14.3:
resolve "^1.17.0"
string.prototype.matchall "^4.0.2"

eslint-scope@^5.0.0:
eslint-scope@^5.0.0, eslint-scope@^5.1.1:
version "5.1.1"
resolved "https://registry.yarnpkg.com/eslint-scope/-/eslint-scope-5.1.1.tgz#e786e59a66cb92b3f6c1fb0d508aab174848f48c"
integrity sha512-2NxwbF/hZ0KpepYN0cNbo+FN6XoK7GaHlQhgx/hIZl6Va0bF45RQOOwhLIy8lQDbuCiadSLCBnH2CFYquit5bw==
Expand All @@ -3476,11 +3541,28 @@ eslint-utils@^2.0.0:
dependencies:
eslint-visitor-keys "^1.1.0"

eslint-utils@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/eslint-utils/-/eslint-utils-3.0.0.tgz#8aebaface7345bb33559db0a1f13a1d2d48c3672"
integrity sha512-uuQC43IGctw68pJA1RgbQS8/NP7rch6Cwd4j3ZBtgo4/8Flj4eGE7ZYSZRN3iq5pVUv6GPdW5Z1RFleo84uLDA==
dependencies:
eslint-visitor-keys "^2.0.0"

eslint-visitor-keys@^1.0.0, eslint-visitor-keys@^1.1.0:
version "1.3.0"
resolved "https://registry.yarnpkg.com/eslint-visitor-keys/-/eslint-visitor-keys-1.3.0.tgz#30ebd1ef7c2fdff01c3a4f151044af25fab0523e"
integrity sha512-6J72N8UNa462wa/KFODt/PJ3IU60SDpC3QXC1Hjc1BXXpfL2C9R5+AU7jhe0F6GREqVMh4Juu+NY7xn+6dipUQ==

eslint-visitor-keys@^2.0.0:
version "2.1.0"
resolved "https://registry.yarnpkg.com/eslint-visitor-keys/-/eslint-visitor-keys-2.1.0.tgz#f65328259305927392c938ed44eb0a5c9b2bd303"
integrity sha512-0rSmRBzXgDzIsD6mGdJgevzgezI534Cer5L/vyMX0kHzT/jiB43jRhd9YUlMGYLQy2zprNmoT8qasCGtY+QaKw==

eslint-visitor-keys@^3.0.0:
version "3.1.0"
resolved "https://registry.yarnpkg.com/eslint-visitor-keys/-/eslint-visitor-keys-3.1.0.tgz#eee4acea891814cda67a7d8812d9647dd0179af2"
integrity sha512-yWJFpu4DtjsWKkt5GeNBBuZMlNcYVs6vRCLoCVEJrTjaSB6LC98gFipNK/erM2Heg/E8mIK+hXG/pJMLK+eRZA==

eslint@^6.1.0:
version "6.8.0"
resolved "https://registry.yarnpkg.com/eslint/-/eslint-6.8.0.tgz#62262d6729739f9275723824302fb227c8c93ffb"
Expand Down Expand Up @@ -4180,7 +4262,7 @@ globalyzer@^0.1.0:
resolved "https://registry.yarnpkg.com/globalyzer/-/globalyzer-0.1.4.tgz#bc8e273afe1ac7c24eea8def5b802340c5cc534f"
integrity sha512-LeguVWaxgHN0MNbWC6YljNMzHkrCny9fzjmEUdnF1kQ7wATFD1RHFRqA1qxaX2tgxGENlcxjOflopBwj3YZiXA==

globby@^11.0.1:
globby@^11.0.1, globby@^11.0.4:
version "11.0.4"
resolved "https://registry.yarnpkg.com/globby/-/globby-11.0.4.tgz#2cbaff77c2f2a62e71e9b2813a67b97a3a3001a5"
integrity sha512-9O4MVG9ioZJ08ffbcyVYyLOJLk5JQ688pJ4eMGLpdWLHq/Wr1D9BlriLQyL0E+jbkuePVZXYFj47QM/v093wHg==
Expand Down Expand Up @@ -4713,6 +4795,13 @@ is-glob@^4.0.0, is-glob@^4.0.1:
dependencies:
is-extglob "^2.1.1"

is-glob@^4.0.3:
version "4.0.3"
resolved "https://registry.yarnpkg.com/is-glob/-/is-glob-4.0.3.tgz#64f61e42cbbb2eec2071a9dac0b28ba1e65d5084"
integrity sha512-xelSayHH36ZgE7ZWhli7pW34hNbNl8Ojv5KVmkJD4hBdD3th8Tfk9vYasLM+mXWOZhFkgZfxhLSnrwRr4elSSg==
dependencies:
is-extglob "^2.1.1"

is-lambda@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/is-lambda/-/is-lambda-1.0.1.tgz#3d9877899e6a53efc0160504cde15f82e6f061d5"
Expand Down Expand Up @@ -8610,6 +8699,13 @@ tsutils@^3.17.1:
dependencies:
tslib "^1.8.1"

tsutils@^3.21.0:
version "3.21.0"
resolved "https://registry.yarnpkg.com/tsutils/-/tsutils-3.21.0.tgz#b48717d394cea6c1e096983eed58e9d61715b623"
integrity sha512-mHKK3iUXL+3UF6xL5k0PEhKRUBKPBCv/+RkEOpjRWxxx27KKRBmmA60A9pgOUvMi8GKhRMPEmjBRPzs2W7O1OA==
dependencies:
tslib "^1.8.1"

tunnel-agent@^0.6.0:
version "0.6.0"
resolved "https://registry.yarnpkg.com/tunnel-agent/-/tunnel-agent-0.6.0.tgz#27a5dea06b36b04a0a9966774b290868f0fc40fd"
Expand Down

0 comments on commit 98fb3d6

Please sign in to comment.