Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .env.demo
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
APP_ENV=<< APP_ENV >>
PORT=<< PORT >>
MONGODB_URL=<< MONGODB_URL >>
24 changes: 24 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
module.exports = {
parser: '@typescript-eslint/parser',
parserOptions: {
project: 'tsconfig.json',
sourceType: 'module',
},
plugins: ['@typescript-eslint/eslint-plugin'],
extends: [
'plugin:@typescript-eslint/recommended',
'plugin:prettier/recommended',
],
root: true,
env: {
node: true,
jest: true,
},
ignorePatterns: ['.eslintrc.js'],
rules: {
'@typescript-eslint/interface-name-prefix': 'off',
'@typescript-eslint/explicit-function-return-type': 'off',
'@typescript-eslint/explicit-module-boundary-types': 'off',
'@typescript-eslint/no-explicit-any': 'off',
},
};
36 changes: 36 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: unit test and e2e test

on: [push, pull_request]

jobs:
unit_test:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [14.x]
steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node-version }}
cache: 'yarn'
- run: |
yarn install --frozen-lockfile
yarn test:unit

e2e_test:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [14.x]
steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node-version }}
cache: 'yarn'
- run: |
yarn install --frozen-lockfile
yarn test:e2e
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@ logs
lerna-debug.log
npm-debug.log
yarn-error.log
yarn.lock
stats.json
package-lock.json

.env
# Runtime data
pids
*.pid
Expand Down
4 changes: 4 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"singleQuote": true,
"trailingComma": "all"
}
110 changes: 110 additions & 0 deletions __tests__/e2e/player/__snapshots__/playerByIdGet.e2e.spec.ts.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`GET /player/5b8ea08eb0b2b900dcb8be53 fail cases should throw NotFoundErrorException if player is not fount 1`] = `
[MockFunction spyHandlerQueryPlayerById] {
"calls": Array [
Array [
"5b8ea08eb0b2b900dcb8be53",
],
],
"results": Array [
Object {
"type": "return",
"value": Promise {},
},
],
}
`;

exports[`GET /player/5b8ea08eb0b2b900dcb8be53 fail cases should throw NotFoundErrorException if player is not fount 2`] = `
[MockFunction spyFindOne] {
"calls": Array [
Array [
Object {
"filter": Object {
"_id": "5b8ea08eb0b2b900dcb8be53",
"status": 1,
},
},
],
],
"results": Array [
Object {
"type": "return",
"value": Promise {},
},
],
}
`;

exports[`GET /player/5b8ea08eb0b2b900dcb8be53 fail cases should throw NotFoundErrorException if player is not fount 3`] = `
Object {
"code": 404,
"message": "player not fount",
"path": "/player/5b8ea08eb0b2b900dcb8be53",
"statusCode": 404,
"type": "NotFoundErrorException",
}
`;

exports[`GET /player/5b8ea08eb0b2b900dcb8be53 fail cases should throw Validation Error if player id is incorrect 1`] = `
Object {
"code": 405,
"message": Array [
Object {
"msg": "{\\"isMongoId\\":\\"playerId must be a mongodb id\\"}",
"path": "playerId",
"value": "aaa",
},
],
"path": "/player/aaa",
"statusCode": 405,
"type": "ValidationErrorException",
}
`;

exports[`GET /player/5b8ea08eb0b2b900dcb8be53 success cases should return player details response 1`] = `
[MockFunction spyHandlerQueryPlayerById] {
"calls": Array [
Array [
"5b8ea08eb0b2b900dcb8be53",
],
],
"results": Array [
Object {
"type": "return",
"value": Promise {},
},
],
}
`;

exports[`GET /player/5b8ea08eb0b2b900dcb8be53 success cases should return player details response 2`] = `
[MockFunction spyFindOne] {
"calls": Array [
Array [
Object {
"filter": Object {
"_id": "5b8ea08eb0b2b900dcb8be53",
"status": 1,
},
},
],
],
"results": Array [
Object {
"type": "return",
"value": Promise {},
},
],
}
`;

exports[`GET /player/5b8ea08eb0b2b900dcb8be53 success cases should return player details response 3`] = `
"<?xml version=\\"1.0\\"?>
<Player>
<id>61cc1f3a428d36921fdcf8d2</id>
<name>name</name>
<position>C</position>
</Player>"
`;
126 changes: 126 additions & 0 deletions __tests__/e2e/player/__snapshots__/playerDelete.e2e.spec.ts.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`DELETE /player/5b8ea08eb0b2b900dcb8be53 fail cases should throw NotFoundErrorException if player is not fount 1`] = `
[MockFunction spyHandlerDeletePlayerById] {
"calls": Array [
Array [
"5b8ea08eb0b2b900dcb8be53",
],
],
"results": Array [
Object {
"type": "return",
"value": Promise {},
},
],
}
`;

exports[`DELETE /player/5b8ea08eb0b2b900dcb8be53 fail cases should throw NotFoundErrorException if player is not fount 2`] = `
[MockFunction spyFindOne] {
"calls": Array [
Array [
Object {
"filter": Object {
"_id": "5b8ea08eb0b2b900dcb8be53",
"status": 1,
},
},
],
],
"results": Array [
Object {
"type": "return",
"value": Promise {},
},
],
}
`;

exports[`DELETE /player/5b8ea08eb0b2b900dcb8be53 fail cases should throw NotFoundErrorException if player is not fount 3`] = `
Object {
"code": 404,
"message": "player not fount",
"path": "/player/5b8ea08eb0b2b900dcb8be53",
"statusCode": 404,
"type": "NotFoundErrorException",
}
`;

exports[`DELETE /player/5b8ea08eb0b2b900dcb8be53 fail cases should throw Validation Error if player id is incorrect 1`] = `
Object {
"code": 405,
"message": Array [
Object {
"msg": "{\\"isMongoId\\":\\"playerId must be a mongodb id\\"}",
"path": "playerId",
"value": "aaa",
},
],
"path": "/player/aaa",
"statusCode": 405,
"type": "ValidationErrorException",
}
`;

exports[`DELETE /player/5b8ea08eb0b2b900dcb8be53 success cases should delete player 1`] = `
[MockFunction spyHandlerDeletePlayerById] {
"calls": Array [
Array [
"5b8ea08eb0b2b900dcb8be53",
],
],
"results": Array [
Object {
"type": "return",
"value": Promise {},
},
],
}
`;

exports[`DELETE /player/5b8ea08eb0b2b900dcb8be53 success cases should delete player 2`] = `
[MockFunction spyFindOne] {
"calls": Array [
Array [
Object {
"filter": Object {
"_id": "5b8ea08eb0b2b900dcb8be53",
"status": 1,
},
},
],
],
"results": Array [
Object {
"type": "return",
"value": Promise {},
},
],
}
`;

exports[`DELETE /player/5b8ea08eb0b2b900dcb8be53 success cases should delete player 3`] = `
[MockFunction spyUpdate] {
"calls": Array [
Array [
Object {
"conditions": Object {
"_id": "5b8ea08eb0b2b900dcb8be53",
},
"update": Object {
"status": 0,
},
},
],
],
"results": Array [
Object {
"type": "return",
"value": Promise {},
},
],
}
`;

exports[`DELETE /player/5b8ea08eb0b2b900dcb8be53 success cases should delete player 4`] = `Object {}`;
67 changes: 67 additions & 0 deletions __tests__/e2e/player/__snapshots__/playerPost.e2e.spec.ts.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`POST /player fail cases should throw Validation Error if request is incorrect 1`] = `
Object {
"code": 405,
"message": Array [
Object {
"msg": "{\\"isString\\":\\"name must be a string\\"}",
"path": "name",
},
],
"path": "/player",
"statusCode": 405,
"type": "ValidationErrorException",
}
`;

exports[`POST /player success cases should create player 1`] = `
[MockFunction spyHandlerCreatePlayer] {
"calls": Array [
Array [
Object {
"name": "name",
"position": "C",
},
],
],
"results": Array [
Object {
"type": "return",
"value": Promise {},
},
],
}
`;

exports[`POST /player success cases should create player 2`] = `
[MockFunction spyCreate] {
"calls": Array [
Array [
Object {
"docs": Object {
"name": "name",
"position": "C",
},
},
],
],
"results": Array [
Object {
"type": "return",
"value": Promise {},
},
],
}
`;

exports[`POST /player success cases should create player 3`] = `
Object {
"createdBy": "system",
"id": "61cc1f3a428d36921fdcf8d2",
"name": "name",
"position": "C",
"status": 1,
"updatedBy": "system",
}
`;
Loading