-
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.
DEV - DELETE user impacts on code + http errors + logout deleted user
- Loading branch information
1 parent
c168ead
commit 770949b
Showing
6 changed files
with
96 additions
and
90 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
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
160 changes: 77 additions & 83 deletions
160
test/data/data-sources/sqlite/sqlite-user-data-source.test.todo.ts
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,97 +1,91 @@ | ||
import { SQLiteUserDataSource } from '../../../../src/data/data-sources/sqlite/sqlite-user-data-source' | ||
import { SQLiteDatabaseWrapper } from '../../../../src/data/interfaces/data-sources/database-wrapper'; | ||
import { UserRequesCreationtModel, UserResponseModel } from '../../../../src/domain/entities/user'; | ||
// import { SQLiteUserDataSource } from '../../../../src/data/data-sources/sqlite/sqlite-user-data-source' | ||
// import { SQLiteDatabaseWrapper } from '../../../../src/data/interfaces/data-sources/database-wrapper'; | ||
// import { UserRequesCreationtModel, UserResponseModel } from '../../../../src/domain/entities/user'; | ||
|
||
// TODO COMPLETE TESTS | ||
describe("PG DataSource", () => { | ||
// // TODO COMPLETE TESTS | ||
// describe("PG DataSource", () => { | ||
|
||
let mockDatabase: SQLiteDatabaseWrapper | ||
// let mockDatabase: SQLiteDatabaseWrapper | ||
|
||
beforeAll(async () => { | ||
mockDatabase = { | ||
all: jest.fn(), | ||
run: jest.fn(), | ||
get: jest.fn(), | ||
// beforeAll(async () => { | ||
// mockDatabase = { | ||
// all: jest.fn(), | ||
// run: jest.fn(), | ||
// get: jest.fn(), | ||
|
||
} | ||
}) | ||
// } | ||
// }) | ||
|
||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
}) | ||
// beforeEach(() => { | ||
// jest.clearAllMocks(); | ||
// }) | ||
|
||
// TODO : AUTO ID | ||
test("getAll", async () => { | ||
const OutputData: UserResponseModel = { | ||
user_id: 1, | ||
last_name: "Smith", | ||
first_name: "John", | ||
email: "[email protected]", | ||
is_admin: false, | ||
valid_email: true, | ||
organisation: "LOV", | ||
country: "France", | ||
user_planned_usage: "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.", | ||
user_creation_date: '2023-08-01 10:30:00' | ||
} | ||
const DbOutputData = { | ||
user_id: 1, | ||
last_name: "Smith", | ||
first_name: "John", | ||
email: "[email protected]", | ||
is_admin: 0, | ||
valid_email: 1, | ||
organisation: "LOV", | ||
country: "France", | ||
user_planned_usage: "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.", | ||
user_creation_date: '2023-08-01 10:30:00' | ||
} | ||
const ds = new SQLiteUserDataSource(mockDatabase); | ||
jest.spyOn(mockDatabase, "all").mockImplementation(() => Promise.resolve({ rows: [{ name: "Smith", user_id: "123" }] })) | ||
const result = await ds.getAll(); | ||
expect(mockDatabase.all).toHaveBeenCalledWith("SELECT * FROM user") | ||
expect(result).toStrictEqual([OutputData]) | ||
}) | ||
// // TODO : AUTO ID | ||
// test("getAll", async () => { | ||
// const OutputData: UserResponseModel = { | ||
// user_id: 1, | ||
// last_name: "Smith", | ||
// first_name: "John", | ||
// email: "[email protected]", | ||
// is_admin: false, | ||
// valid_email: true, | ||
// organisation: "LOV", | ||
// country: "France", | ||
// user_planned_usage: "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.", | ||
// user_creation_date: '2023-08-01 10:30:00' | ||
// } | ||
// const DbOutputData = { | ||
// user_id: 1, | ||
// last_name: "Smith", | ||
// first_name: "John", | ||
// email: "[email protected]", | ||
// is_admin: 0, | ||
// valid_email: 1, | ||
// organisation: "LOV", | ||
// country: "France", | ||
// user_planned_usage: "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.", | ||
// user_creation_date: '2023-08-01 10:30:00' | ||
// } | ||
// const ds = new SQLiteUserDataSource(mockDatabase); | ||
// jest.spyOn(mockDatabase, "all").mockImplementation(() => Promise.resolve({ rows: [{ name: "Smith", user_id: "123" }] })) | ||
// const result = await ds.getAll(); | ||
// expect(mockDatabase.all).toHaveBeenCalledWith("SELECT * FROM user") | ||
// expect(result).toStrictEqual([OutputData]) | ||
// }) | ||
|
||
|
||
describe('create method', () => { | ||
test('should insert a user into the database', async () => { | ||
const ds = new SQLiteUserDataSource(mockDatabase); | ||
const inputData: UserRequesCreationtModel = { | ||
last_name: "Smith", | ||
first_name: "John", | ||
email: "[email protected]", | ||
password: "123test!", | ||
organisation: "LOV", | ||
country: "France", | ||
user_planned_usage: "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua." | ||
} | ||
await ds.create(inputData); | ||
expect(mockDatabase.run).toHaveBeenCalledWith("INSERT INTO user (name) VALUES ($1)", ["Smith"]) | ||
}); | ||
// describe('create method', () => { | ||
// test('should insert a user into the database', async () => { | ||
// const ds = new SQLiteUserDataSource(mockDatabase); | ||
// const inputData: UserRequesCreationtModel = { | ||
// last_name: "Smith", | ||
// first_name: "John", | ||
// email: "[email protected]", | ||
// password: "123test!", | ||
// organisation: "LOV", | ||
// country: "France", | ||
// user_planned_usage: "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua." | ||
// } | ||
// await ds.create(inputData); | ||
// expect(mockDatabase.run).toHaveBeenCalledWith("INSERT INTO user (name) VALUES ($1)", ["Smith"]) | ||
// }); | ||
|
||
|
||
}); | ||
// }); | ||
|
||
|
||
// test("deleteOne", async () => { | ||
// const ds = new SQLiteUserDataSource(mockDatabase); | ||
// await ds.deleteOne("1"); | ||
// expect(mockDatabase.query).toHaveBeenCalledWith("delete tb_user where user_id = $1", ["1"]) | ||
// }) | ||
// // test("updateOne", async () => { | ||
// // const ds = new SQLiteUserDataSource(mockDatabase); | ||
// // await ds.updateOne("1", { name: "Ramon" }); | ||
// // expect(mockDatabase.query).toHaveBeenCalledWith("update tb_user set name = $1 where user_id = $2", ["Ramon", "1"]) | ||
// // }) | ||
|
||
// test("updateOne", async () => { | ||
// const ds = new SQLiteUserDataSource(mockDatabase); | ||
// await ds.updateOne("1", { name: "Ramon" }); | ||
// expect(mockDatabase.query).toHaveBeenCalledWith("update tb_user set name = $1 where user_id = $2", ["Ramon", "1"]) | ||
// }) | ||
// // test("getOne", async () => { | ||
// // const ds = new SQLiteUserDataSource(mockDatabase); | ||
// // jest.spyOn(mockDatabase, "query").mockImplementation(() => Promise.resolve({ rows: [{ user_id: "123", name: "Smith", }] })) | ||
// // const result = await ds.getOne("123"); | ||
// // expect(result).toStrictEqual({ name: "Smith", user_id: "123" }) | ||
// // expect(mockDatabase.query).toHaveBeenCalledWith("select * from tb_user where user_id = $1 limit 1", ["123"]) | ||
// // }) | ||
|
||
// test("getOne", async () => { | ||
// const ds = new SQLiteUserDataSource(mockDatabase); | ||
// jest.spyOn(mockDatabase, "query").mockImplementation(() => Promise.resolve({ rows: [{ user_id: "123", name: "Smith", }] })) | ||
// const result = await ds.getOne("123"); | ||
// expect(result).toStrictEqual({ name: "Smith", user_id: "123" }) | ||
// expect(mockDatabase.query).toHaveBeenCalledWith("select * from tb_user where user_id = $1 limit 1", ["123"]) | ||
// }) | ||
|
||
}) | ||
// }) |