forked from filoscoder/tenstack-starter
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1069b5e
commit 98a98e7
Showing
45 changed files
with
677 additions
and
226 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
{ | ||
"root": true, | ||
"parser": "@typescript-eslint/parser", | ||
"parserOptions": { | ||
"ecmaVersion": "latest", | ||
"sourceType": "module", | ||
"project": "./tsconfig.json" | ||
}, | ||
"plugins": ["import", "prettier"], | ||
"ignorePatterns": ["node_modules/*", "dist/*", "jest*", "ecosystem*"], | ||
"extends": [ | ||
"plugin:@typescript-eslint/recommended", | ||
"prettier" | ||
], | ||
"rules": { | ||
"@typescript-eslint/explicit-module-boundary-types": "off", | ||
"@typescript-eslint/no-empty-interface": "off", | ||
"@typescript-eslint/ban-types": "off", | ||
"@typescript-eslint/ban-ts-comment": "off", | ||
"@typescript-eslint/no-non-null-assertion": "off", | ||
"@typescript-eslint/no-explicit-any": "off", | ||
"@typescript-eslint/no-unused-vars": ["error", { | ||
"argsIgnorePattern": "^_" | ||
}], | ||
"import/order": ["error"], | ||
"prettier/prettier": [ | ||
"error", | ||
{ | ||
"endOfLine": "auto" | ||
} | ||
] | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
{ | ||
"parser": "typescript", | ||
"semi": true, | ||
"singleQuote": true, | ||
"singleQuote": false, | ||
"tabWidth": 2, | ||
"trailingComma": "all" | ||
"trailingComma": "all", | ||
"printWidth": 80 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"editor.experimental.stickyScroll.enabled": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import supertest, { SuperAgentTest } from "supertest"; | ||
|
||
import { createApp } from "@/app"; | ||
|
||
// let dbConnection: Mongoose; | ||
|
||
export const initAgent = async (): Promise<SuperAgentTest> => { | ||
const app = createApp(); | ||
const agent = supertest.agent(app); | ||
// dbConnection = await mongoDbConnection(); | ||
// await agent.post("/api/v2/auth/signin").send({ | ||
// email: testUser.email, | ||
// password: testUser.password, | ||
// }); | ||
|
||
return agent; | ||
}; | ||
|
||
// export const closeClients = async (): Promise<void> => { | ||
// await dbConnection.disconnect(); | ||
// }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import { SuperAgentTest } from "supertest"; | ||
import HttpStatus, { OK, BAD_REQUEST } from "http-status/lib"; | ||
import { initAgent } from "./helpers"; | ||
import CONFIG from "@/config"; | ||
|
||
let agent: SuperAgentTest; | ||
|
||
beforeAll(async () => { | ||
agent = await initAgent(); | ||
}); | ||
|
||
describe("[UNIT] => HOME", () => { | ||
describe("GET: '/'", () => { | ||
it("Should return API app information", async () => { | ||
const response = await agent.get(`/api/${CONFIG.APP.VER}`); | ||
expect(response.status).toBe(OK); | ||
expect(Object.keys(response.body.data)).toEqual([ | ||
"NAME", | ||
"VERSION", | ||
"VER", | ||
"DESCRIPTION", | ||
"AUTHORS", | ||
"PORT", | ||
"ENV", | ||
]); | ||
}); | ||
|
||
it.each` | ||
query | field | expectedStatus | ||
${"name"} | ${"NAME"} | ${OK} | ||
${"version"} | ${"VERSION"} | ${OK} | ||
${"description"} | ${"DESCRIPTION"} | ${OK} | ||
${"authors"} | ${"AUTHORS"} | ${OK} | ||
${"port"} | ${"PORT"} | ${OK} | ||
${"env"} | ${"ENV"} | ${OK} | ||
`( | ||
"Should return CONFIG.APP[$field] value when query.key is `$query`", | ||
async ({ | ||
query, | ||
field, | ||
expectedStatus, | ||
}: { | ||
query: string; | ||
field: keyof typeof CONFIG.APP; | ||
expectedStatus: string; | ||
}) => { | ||
const response = await agent | ||
.get(`/api/${CONFIG.APP.VER}`) | ||
.query({ key: query }); | ||
|
||
expect(response.body.status).toBe(expectedStatus); | ||
expect(response.body.data[field]).toBe(CONFIG.APP[field]); | ||
}, | ||
); | ||
|
||
it("Should return 400 status Validation Error", async () => { | ||
const invalidQuery = "invalid-field"; | ||
const response = await agent | ||
.get(`/api/${CONFIG.APP.VER}`) | ||
.query({ key: invalidQuery }); | ||
|
||
expect(response.body.status).toBe(BAD_REQUEST); | ||
expect(response.body.message).toBe(HttpStatus[BAD_REQUEST]); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
const { defaults: tsjPreset } = require("ts-jest/presets"); | ||
|
||
module.exports = { | ||
globals: { | ||
"ts-jest": { | ||
tsconfig: "tsconfig.json", | ||
diagnostics: false, | ||
}, | ||
}, | ||
preset: "ts-jest", | ||
moduleFileExtensions: ["ts", "js", "json"], | ||
transform: { | ||
"^.+\\.(ts|tsx)$": "ts-jest", | ||
...tsjPreset.transform, | ||
}, | ||
testPathIgnorePatterns: ["dist"], | ||
testMatch: ["**/__tests__/**/*.test.(ts|js)"], | ||
testEnvironment: "node", | ||
moduleNameMapper: { | ||
"@/(.*)": "<rootDir>/src/$1", | ||
}, | ||
watchPlugins: [ | ||
"jest-watch-typeahead/filename", | ||
"jest-watch-typeahead/testname", | ||
], | ||
coverageThreshold: { | ||
global: { | ||
branches: 1, | ||
functions: 1, | ||
lines: 1, | ||
statements: 1, | ||
}, | ||
}, | ||
coverageReporters: ["json", "lcov", "text", "clover"], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { OK } from "http-status/lib"; | ||
import { HomeServices } from "./services"; | ||
import { getAppInfoQuery } from "@/types/request/home"; | ||
import { apiResponse } from "@/helpers/apiResponse"; | ||
|
||
export class HomeController { | ||
/** | ||
* @description Gets the API information. | ||
* @param {Req} req | ||
* @param {Res} res | ||
*/ | ||
static getAppInfo = async (req: Req, res: Res, next: NextFn) => { | ||
try { | ||
const appInfoKey = req.query.key as getAppInfoQuery; | ||
const homeServices = new HomeServices(); | ||
const result = await homeServices.getAppInfo(appInfoKey); | ||
|
||
res.status(OK).json(apiResponse(result)); | ||
} catch (error) { | ||
next(error); | ||
} | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export { HomeController } from "./controller"; | ||
export { appKeyValidator } from "./validators"; |
Oops, something went wrong.