Skip to content

Commit

Permalink
feat: added tests (#67)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tolfx committed Aug 14, 2022
1 parent dfbc53d commit d46a0f2
Show file tree
Hide file tree
Showing 11 changed files with 80 additions and 9 deletions.
14 changes: 14 additions & 0 deletions apps/api/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// eslint-disable-next-line no-undef
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
clearMocks: true,
coverageDirectory: "coverage",
coverageProvider: "v8",
testMatch: [
"**/test/**/*.[t]s?(x)",
"**/__tests__/**/*.[t]s?(x)",
"**/?(*.)+(spec|test).[t]s?(x)"
],
testTimeout: 2000,
};
7 changes: 6 additions & 1 deletion apps/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@
"start": "node ./build/Main.js",
"build": "tsc -b",
"dev": "nodemon ./build/Main.js",
"lint": "eslint ./src --ext .ts"
"lint": "eslint ./src --ext .ts",
"test": "jest"
},
"repository": {
"type": "git",
Expand All @@ -76,6 +77,7 @@
"@types/figlet": "^1.5.4",
"@types/graphql-resolvers": "^0.3.1",
"@types/inquirer": "^8.2.1",
"@types/jest": "^28.1.6",
"@types/jsonwebtoken": "^8.5.5",
"@types/mongoose-auto-increment": "^5.0.34",
"@types/node": "^16.4.10",
Expand All @@ -94,8 +96,11 @@
"eslint": "^8.14.0",
"eslint-config-custom": "*",
"interfaces": "*",
"jest": "^28.1.3",
"lib": "*",
"ts-jest": "^28.0.7",
"tsconfig": "*",
"tslib": "^2.4.0",
"typescript": "^4.3.5"
}
}
11 changes: 11 additions & 0 deletions apps/api/src/Mods/Map.mod.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import "./Map.mod";

describe('map mod', () =>
{
it('should return an array', () =>
{
const map = new Map<string, string>();
map.set("a", "b");
expect(map.array()).toEqual(["b"]);
})
})
11 changes: 11 additions & 0 deletions apps/api/src/Mods/String.mod.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import "./String.mod";

describe('string mod', () =>
{
it("first letter should be uppercase", () =>
{
const s = "abc";
expect(s).toEqual("abc");
expect(s.firstLetterUpperCase()).toEqual("Abc");
});
});
2 changes: 1 addition & 1 deletion apps/api/test/Customer.rest
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
POST http://localhost:8080/v2/customers/authenticate
POST http://localhost:3001/v2/customers/authenticate
Content-Type: application/json

{
Expand Down
4 changes: 2 additions & 2 deletions apps/api/test/Orders.rest
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
POST http://localhost:8080/v2/orders/place
POST http://localhost:3001/v2/orders/place
Content-Type: application/json
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJkYXRhIjp7ImlkIjoxLCJlbWFpbCI6InRlc3RAdG9sZml4LmNvbSJ9LCJleHAiOjE2NDc0Mzc0MjYsImlhdCI6MTY0NzM1MTAyNn0.6U6SUhsq76Ad0uDjm9Z3XbiKDY-YXZ320i6WRcvGnJA
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJkYXRhIjp7ImlkIjoxLCJlbWFpbCI6InRlc3RAdG9sZml4LmNvbSJ9LCJleHAiOjE2NTk5Nzc4NzcsImlhdCI6MTY1OTg5MTQ3N30.nikGc2EmOdGeG-vagUJ9eD1ZkFLA9fdUh7wGbxLFJic

{
"payment_method": "credit_card",
Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@
"cpg-api:build": "tsc --project ./apps/api/tsconfig.json --watch",
"cpg-api:dev": "turbo run dev --scope=cpg-api",
"cpg-customer:dev": "turbo run dev --scope=cpg-customer",
"format": "npx eslint \"**/*.{ts,tsx}\" --fix"
"format": "npx eslint \"**/*.{ts,tsx}\" --fix",
"test": "turbo run test"
},
"devDependencies": {
"turbo": "latest"
"turbo": "^1.4.3"
},
"engines": {
"npm": ">=7.0.0",
"node": ">=14.0.0"
},
"packageManager": "[email protected]",
"dependencies": {}
"packageManager": "[email protected]"
}
13 changes: 13 additions & 0 deletions packages/lib/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
clearMocks: true,
coverageDirectory: "coverage",
coverageProvider: "v8",
testMatch: [
"**/test/**/*.[t]s?(x)",
"**/__tests__/**/*.[t]s?(x)",
"**/?(*.)+(spec|test).[t]s?(x)"
],
testTimeout: 2000,
};
6 changes: 5 additions & 1 deletion packages/lib/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,13 @@
"test": "jest"
},
"devDependencies": {
"@types/jest": "^28.1.6",
"@typescript-eslint/eslint-plugin": "^5.33.0",
"@typescript-eslint/parser": "^5.33.0",
"eslint": "^8.22.0",
"eslint-config-custom": "*"
"eslint-config-custom": "*",
"jest": "^28.1.3",
"ts-jest": "^28.0.7",
"tslib": "^2.4.0"
}
}
9 changes: 9 additions & 0 deletions packages/lib/src/AW.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import AW from "./AW";

describe("AW", () =>
{
it("should return a promise", async () =>
{
expect(AW(await Promise.resolve())).toBeInstanceOf(Promise);
});
});
4 changes: 4 additions & 0 deletions turbo.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
"lint": {
"outputs": []
},
"test": {
"outputs": ["coverage/**"],
"dependsOn": []
},
"dev": {
"cache": false
}
Expand Down

0 comments on commit d46a0f2

Please sign in to comment.