-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ESLint Configuration PreCommit format and Test
- Loading branch information
1 parent
1a54b1d
commit 0f709f6
Showing
33 changed files
with
1,009 additions
and
884 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,2 @@ | ||
npm run pre-commit | ||
npm run test |
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,5 @@ | ||
{ | ||
"semi": true, | ||
"tabWidth": 2, | ||
"useTabs": 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
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 |
---|---|---|
|
@@ -5,74 +5,82 @@ import User from "../src/sequelize/models/users"; | |
import * as userServices from "../src/services/user.service"; | ||
import sequelize, { connect } from "../src/config/dbConnection"; | ||
|
||
const userData:any = { | ||
name: 'yvanna', | ||
username: 'testuser', | ||
email: '[email protected]', | ||
password:'test1234', | ||
}; | ||
const userData: any = { | ||
name: "yvanna", | ||
username: "testuser", | ||
email: "[email protected]", | ||
password: "test1234", | ||
}; | ||
|
||
const loginData:any = { | ||
email:'[email protected]', | ||
password:"test1234" | ||
} | ||
const loginData: any = { | ||
email: "[email protected]", | ||
password: "test1234", | ||
}; | ||
describe("Testing user Routes", () => { | ||
beforeAll(async () => { | ||
try { | ||
await connect(); | ||
await User.destroy({truncate:true}) | ||
} catch (error) { | ||
sequelize.close(); | ||
} | ||
}, 20000); | ||
beforeAll(async () => { | ||
try { | ||
await connect(); | ||
await User.destroy({ truncate: true }); | ||
} catch (error) { | ||
sequelize.close(); | ||
} | ||
}, 20000); | ||
|
||
afterAll(async () => { | ||
await User.destroy({ truncate: true }); | ||
await sequelize.close(); | ||
}); | ||
describe("Testing user authentication", () => { | ||
test('should return 201 and create a new user when registering successfully', async () => { | ||
const response = await request(app) | ||
.post('/api/v1/users/register') | ||
.send(userData); | ||
expect(response.status).toBe(201); }, 20000); | ||
afterAll(async () => { | ||
await User.destroy({ truncate: true }); | ||
await sequelize.close(); | ||
}); | ||
describe("Testing user authentication", () => { | ||
test("should return 201 and create a new user when registering successfully", async () => { | ||
const response = await request(app) | ||
.post("/api/v1/users/register") | ||
.send(userData); | ||
expect(response.status).toBe(201); | ||
}, 20000); | ||
|
||
test('should return 409 when registering with an existing email', async () => { | ||
User.create(userData) | ||
const response = await request(app) | ||
.post('/api/v1/users/register') | ||
.send(userData); | ||
expect(response.status).toBe(409); }, 20000); | ||
test("should return 409 when registering with an existing email", async () => { | ||
User.create(userData); | ||
const response = await request(app) | ||
.post("/api/v1/users/register") | ||
.send(userData); | ||
expect(response.status).toBe(409); | ||
}, 20000); | ||
|
||
test('should return 400 when registering with an invalid credential', async () => { | ||
const userData = { | ||
email: '[email protected]', name: "", username: 'existinguser', }; | ||
const response = await request(app) | ||
.post('/api/v1/users/register') | ||
.send(userData); | ||
|
||
expect(response.status).toBe(400); }, 20000); }); | ||
test("should return 400 when registering with an invalid credential", async () => { | ||
const userData = { | ||
email: "[email protected]", | ||
name: "", | ||
username: "existinguser", | ||
}; | ||
const response = await request(app) | ||
.post("/api/v1/users/register") | ||
.send(userData); | ||
|
||
test("should return all users in db --> given '/api/v1/users'", async () => { | ||
const spy = jest.spyOn(User, "findAll"); | ||
const spy2 = jest.spyOn(userServices, "getAllUsers"); | ||
const response = await request(app).get("/api/v1/users"); | ||
expect(spy).toHaveBeenCalled(); | ||
expect(spy2).toHaveBeenCalled(); | ||
}, 20000); | ||
test("Should return status 401 to indicate Unauthorized user",async() =>{ | ||
const loggedInUser ={ | ||
email:userData.email, | ||
password:"test", | ||
}; | ||
const spyonOne = jest.spyOn(User,"findOne").mockResolvedValueOnce({ | ||
//@ts-ignore | ||
email:userData.email, | ||
password:loginData.password, | ||
}); | ||
const response = await request(app).post("/api/v1/users/login") | ||
.send(loggedInUser) | ||
expect(response.body.status).toBe(401); | ||
spyonOne.mockRestore(); | ||
}); | ||
}) | ||
expect(response.status).toBe(400); | ||
}, 20000); | ||
}); | ||
}); | ||
|
||
test("should return all users in db --> given '/api/v1/users'", async () => { | ||
const spy = jest.spyOn(User, "findAll"); | ||
const spy2 = jest.spyOn(userServices, "getAllUsers"); | ||
const response = await request(app).get("/api/v1/users"); | ||
expect(spy).toHaveBeenCalled(); | ||
expect(spy2).toHaveBeenCalled(); | ||
}, 20000); | ||
test("Should return status 401 to indicate Unauthorized user", async () => { | ||
const loggedInUser = { | ||
email: userData.email, | ||
password: "test", | ||
}; | ||
const spyonOne = jest.spyOn(User, "findOne").mockResolvedValueOnce({ | ||
//@ts-ignore | ||
email: userData.email, | ||
password: loginData.password, | ||
}); | ||
const response = await request(app) | ||
.post("/api/v1/users/login") | ||
.send(loggedInUser); | ||
expect(response.body.status).toBe(401); | ||
spyonOne.mockRestore(); | ||
}); |
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,51 @@ | ||
const eslint = require("@eslint/js"); | ||
const tseslint = require("typescript-eslint"); | ||
|
||
module.exports = tseslint.config( | ||
{ | ||
ignores: ["**/__test__", "**/*.json"], | ||
}, | ||
eslint.configs.recommended, | ||
...tseslint.configs.recommended, | ||
{ | ||
languageOptions: { | ||
parserOptions: { | ||
project: true, | ||
ecmaVersion: 2020, | ||
}, | ||
}, | ||
}, | ||
{ | ||
files: ["*.ts", "*.js"], | ||
...tseslint.configs.disableTypeChecked, | ||
}, | ||
{ | ||
files: ["*.test *.js"], | ||
rules: { | ||
"@typescript-eslint/no-unused-vars": 0, | ||
"@typescript-eslint/no-unsafe-call": 0, | ||
languageOptions: { | ||
globals: { | ||
it: "readonly", | ||
describe: "readonly", | ||
}, | ||
}, | ||
}, | ||
}, | ||
{ | ||
rules: { | ||
semi: "error", | ||
"@typescript-eslint/no-unused-vars": 2, | ||
"@typescript-eslint/no-explicit-any": 0, | ||
"@typescript-eslint/no-var-requires": 0, | ||
"no-shadow": [2, { allow: ["req", "res", "err"] }], | ||
"new-cap": 0, | ||
"one-var-declaration-per-line": 0, | ||
"consistent-return": 0, | ||
"no-param-reassign": 0, | ||
"comma-dangle": 0, | ||
"no-undef": 0, | ||
curly: ["error", "multi-line"], | ||
}, | ||
}, | ||
); |
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,9 @@ | ||
eslint: | ||
enabled: true | ||
file_patterns: | ||
- "*.js" | ||
- "*.ts" | ||
enabled_plugins: | ||
- eslint-plugin-import | ||
- eslint-plugin-prettier | ||
- eslint-plugin:@typescript-eslint |
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 |
---|---|---|
@@ -1,11 +1,11 @@ | ||
/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */ | ||
module.exports = { | ||
preset: "ts-jest", | ||
testEnvironment: "node", | ||
testMatch: ["**/**/*.test.ts"], | ||
verbose: true, | ||
forceExit: true, | ||
clearMocks: true, | ||
resetMocks: true, | ||
restoreMocks: true, | ||
preset: "ts-jest", | ||
testEnvironment: "node", | ||
testMatch: ["**/**/*.test.ts"], | ||
verbose: true, | ||
forceExit: true, | ||
clearMocks: true, | ||
resetMocks: true, | ||
restoreMocks: true, | ||
}; |
Oops, something went wrong.