diff --git a/src/presentation/http/router/auth.test.ts b/src/presentation/http/router/auth.test.ts index 1bb51adbf..6fdcc7934 100644 --- a/src/presentation/http/router/auth.test.ts +++ b/src/presentation/http/router/auth.test.ts @@ -21,10 +21,15 @@ describe('Auth API', () => { test('Returns 200 when refresh token is valid and expiration date has not passed', async () => { const refreshToken = 'pv-jIqfPj2'; + /** + * Create test user + */ + const user = await global.db.insertUser(); + /** * Insert session data to the DB with tomorrow expiration date */ - await global.db.query(`INSERT INTO public.user_sessions ("user_id", "refresh_token", "refresh_token_expires_at") VALUES (1, '${refreshToken}', CURRENT_DATE + INTERVAL '1 day')`); + await global.db.query(`INSERT INTO public.user_sessions ("user_id", "refresh_token", "refresh_token_expires_at") VALUES (${user.id}, '${refreshToken}', CURRENT_DATE + INTERVAL '1 day')`); const response = await global.api?.fakeRequest({ method: 'POST', diff --git a/src/tests/test-data/note-teams.json b/src/tests/test-data/note-teams.json deleted file mode 100644 index 6c4ecfb3e..000000000 --- a/src/tests/test-data/note-teams.json +++ /dev/null @@ -1,14 +0,0 @@ -[ - { - "id": 1, - "note_id": 2, - "user_id": 2, - "role": 0 - }, - { - "id": 2, - "note_id": 3, - "user_id": 1, - "role": 0 - } -] \ No newline at end of file diff --git a/src/tests/test-data/notes-relations.json b/src/tests/test-data/notes-relations.json deleted file mode 100644 index bd8e4eb8e..000000000 --- a/src/tests/test-data/notes-relations.json +++ /dev/null @@ -1,12 +0,0 @@ -[ - { - "id": 2, - "note_id": 54, - "parent_id": 55 - }, - { - "id": 3, - "note_id": 56, - "parent_id": 54 - } -] \ No newline at end of file diff --git a/src/tests/test-data/notes-settings.json b/src/tests/test-data/notes-settings.json deleted file mode 100644 index 52d3f1d57..000000000 --- a/src/tests/test-data/notes-settings.json +++ /dev/null @@ -1,41 +0,0 @@ -[ - { - "id": 2, - "note_id": 2, - "custom_hostname": "codex.so", - "is_public": true, - "invitation_hash": "Hzh2hy4igf" - }, - - { - "id": 3, - "note_id": 3, - "custom_hostname": "codex.so", - "is_public": true, - "invitation_hash": "E2zRXv3cp-" - }, - - { - "id": 4, - "note_id": 4, - "custom_hostname": "codex.so", - "is_public": false, - "invitation_hash": "Lw5kIwwo4_" - }, - - { - "id": 54, - "note_id": 54, - "custom_hostname": "codex.so", - "is_public": true, - "invitation_hash": "FfAwyaR80C" - }, - - { - "id": 55, - "note_id": 56, - "custom_hostname": "codex.so", - "is_public": true, - "invitation_hash": "HgdwyaC9g7R" - } -] diff --git a/src/tests/test-data/notes.json b/src/tests/test-data/notes.json deleted file mode 100644 index 1cefc4dde..000000000 --- a/src/tests/test-data/notes.json +++ /dev/null @@ -1,442 +0,0 @@ -[ - { - "id": 2, - "public_id": "TJmEb89e0l", - "creator_id": 1, - "content": {}, - "created_at": "2023-10-16T13:49:19.000Z", - "updated_at": "2023-10-16T13:49:19.000Z" - }, - { - "id": 3, - "public_id": "Pq1T9vc23Q", - "creator_id": 1, - "content": {}, - "created_at": "2023-10-16T13:49:19.000Z", - "updated_at": "2023-10-16T13:49:19.000Z" - }, - { - "id": 4, - "public_id": "73NdxFZ4k7", - "creator_id": 1, - "content": {}, - "created_at": "2023-10-16T13:49:19.000Z", - "updated_at": "2023-10-16T13:49:19.000Z" - }, - { - "id": 5, - "public_id": "99999903", - "creator_id": 4, - "content": {}, - "created_at": "2023-10-16T13:49:3.000Z", - "updated_at": "2023-10-16T13:49:3.000Z" - }, - { - "id": 6, - "public_id": "99999904", - "creator_id": 4, - "content": {}, - "created_at": "2023-10-16T13:49:4.000Z", - "updated_at": "2023-10-16T13:49:4.000Z" - }, - { - "id": 7, - "public_id": "99999905", - "creator_id": 4, - "content": {}, - "created_at": "2023-10-16T13:49:5.000Z", - "updated_at": "2023-10-16T13:49:5.000Z" - }, - { - "id": 8, - "public_id": "99999906", - "creator_id": 4, - "content": {}, - "created_at": "2023-10-16T13:49:6.000Z", - "updated_at": "2023-10-16T13:49:6.000Z" - }, - { - "id": 9, - "public_id": "99999907", - "creator_id": 4, - "content": {}, - "created_at": "2023-10-16T13:49:7.000Z", - "updated_at": "2023-10-16T13:49:7.000Z" - }, - { - "id": 10, - "public_id": "99999908", - "creator_id": 4, - "content": {}, - "created_at": "2023-10-16T13:49:8.000Z", - "updated_at": "2023-10-16T13:49:8.000Z" - }, - { - "id": 11, - "public_id": "99999909", - "creator_id": 4, - "content": {}, - "created_at": "2023-10-16T13:49:9.000Z", - "updated_at": "2023-10-16T13:49:9.000Z" - }, - { - "id": 12, - "public_id": "99999910", - "creator_id": 4, - "content": {}, - "created_at": "2023-10-16T13:49:10.000Z", - "updated_at": "2023-10-16T13:49:10.000Z" - }, - { - "id": 13, - "public_id": "99999911", - "creator_id": 4, - "content": {}, - "created_at": "2023-10-16T13:49:11.000Z", - "updated_at": "2023-10-16T13:49:11.000Z" - }, - { - "id": 14, - "public_id": "99999912", - "creator_id": 4, - "content": {}, - "created_at": "2023-10-16T13:49:12.000Z", - "updated_at": "2023-10-16T13:49:12.000Z" - }, - { - "id": 15, - "public_id": "99999913", - "creator_id": 4, - "content": {}, - "created_at": "2023-10-16T13:49:13.000Z", - "updated_at": "2023-10-16T13:49:13.000Z" - }, - { - "id": 16, - "public_id": "99999914", - "creator_id": 4, - "content": {}, - "created_at": "2023-10-16T13:49:14.000Z", - "updated_at": "2023-10-16T13:49:14.000Z" - }, - { - "id": 17, - "public_id": "99999915", - "creator_id": 4, - "content": {}, - "created_at": "2023-10-16T13:49:15.000Z", - "updated_at": "2023-10-16T13:49:15.000Z" - }, - { - "id": 18, - "public_id": "99999916", - "creator_id": 4, - "content": {}, - "created_at": "2023-10-16T13:49:16.000Z", - "updated_at": "2023-10-16T13:49:16.000Z" - }, - { - "id": 19, - "public_id": "99999917", - "creator_id": 4, - "content": {}, - "created_at": "2023-10-16T13:49:17.000Z", - "updated_at": "2023-10-16T13:49:17.000Z" - }, - { - "id": 20, - "public_id": "99999918", - "creator_id": 4, - "content": {}, - "created_at": "2023-10-16T13:49:18.000Z", - "updated_at": "2023-10-16T13:49:18.000Z" - }, - { - "id": 21, - "public_id": "99999919", - "creator_id": 4, - "content": {}, - "created_at": "2023-10-16T13:49:19.000Z", - "updated_at": "2023-10-16T13:49:19.000Z" - }, - { - "id": 22, - "public_id": "99999920", - "creator_id": 4, - "content": {}, - "created_at": "2023-10-16T13:49:20.000Z", - "updated_at": "2023-10-16T13:49:20.000Z" - }, - { - "id": 23, - "public_id": "99999921", - "creator_id": 4, - "content": {}, - "created_at": "2023-10-16T13:49:21.000Z", - "updated_at": "2023-10-16T13:49:21.000Z" - }, - { - "id": 24, - "public_id": "99999922", - "creator_id": 4, - "content": {}, - "created_at": "2023-10-16T13:49:22.000Z", - "updated_at": "2023-10-16T13:49:22.000Z" - }, - { - "id": 25, - "public_id": "99999923", - "creator_id": 4, - "content": {}, - "created_at": "2023-10-16T13:49:23.000Z", - "updated_at": "2023-10-16T13:49:23.000Z" - }, - { - "id": 26, - "public_id": "99999924", - "creator_id": 4, - "content": {}, - "created_at": "2023-10-16T13:49:24.000Z", - "updated_at": "2023-10-16T13:49:24.000Z" - }, - { - "id": 27, - "public_id": "99999925", - "creator_id": 4, - "content": {}, - "created_at": "2023-10-16T13:49:25.000Z", - "updated_at": "2023-10-16T13:49:25.000Z" - }, - { - "id": 28, - "public_id": "99999926", - "creator_id": 4, - "content": {}, - "created_at": "2023-10-16T13:49:26.000Z", - "updated_at": "2023-10-16T13:49:26.000Z" - }, - { - "id": 29, - "public_id": "99999927", - "creator_id": 4, - "content": {}, - "created_at": "2023-10-16T13:49:27.000Z", - "updated_at": "2023-10-16T13:49:27.000Z" - }, - { - "id": 30, - "public_id": "99999928", - "creator_id": 4, - "content": {}, - "created_at": "2023-10-16T13:49:28.000Z", - "updated_at": "2023-10-16T13:49:28.000Z" - }, - { - "id": 31, - "public_id": "99999929", - "creator_id": 4, - "content": {}, - "created_at": "2023-10-16T13:49:29.000Z", - "updated_at": "2023-10-16T13:49:29.000Z" - }, - { - "id": 32, - "public_id": "99999930", - "creator_id": 4, - "content": {}, - "created_at": "2023-10-16T13:49:30.000Z", - "updated_at": "2023-10-16T13:49:30.000Z" - }, - { - "id": 33, - "public_id": "99999931", - "creator_id": 4, - "content": {}, - "created_at": "2023-10-16T13:49:31.000Z", - "updated_at": "2023-10-16T13:49:31.000Z" - }, - { - "id": 34, - "public_id": "99999932", - "creator_id": 4, - "content": {}, - "created_at": "2023-10-16T13:49:32.000Z", - "updated_at": "2023-10-16T13:49:32.000Z" - }, - { - "id": 35, - "public_id": "99999933", - "creator_id": 4, - "content": {}, - "created_at": "2023-10-16T13:49:33.000Z", - "updated_at": "2023-10-16T13:49:33.000Z" - }, - { - "id": 36, - "public_id": "99999934", - "creator_id": 4, - "content": {}, - "created_at": "2023-10-16T13:49:34.000Z", - "updated_at": "2023-10-16T13:49:34.000Z" - }, - { - "id": 37, - "public_id": "99999935", - "creator_id": 4, - "content": {}, - "created_at": "2023-10-16T13:49:35.000Z", - "updated_at": "2023-10-16T13:49:35.000Z" - }, - { - "id": 38, - "public_id": "99999936", - "creator_id": 4, - "content": {}, - "created_at": "2023-10-16T13:49:36.000Z", - "updated_at": "2023-10-16T13:49:36.000Z" - }, - { - "id": 39, - "public_id": "99999937", - "creator_id": 4, - "content": {}, - "created_at": "2023-10-16T13:49:37.000Z", - "updated_at": "2023-10-16T13:49:37.000Z" - }, - { - "id": 40, - "public_id": "99999938", - "creator_id": 4, - "content": {}, - "created_at": "2023-10-16T13:49:38.000Z", - "updated_at": "2023-10-16T13:49:38.000Z" - }, - { - "id": 41, - "public_id": "99999939", - "creator_id": 4, - "content": {}, - "created_at": "2023-10-16T13:49:39.000Z", - "updated_at": "2023-10-16T13:49:39.000Z" - }, - { - "id": 42, - "public_id": "99999940", - "creator_id": 4, - "content": {}, - "created_at": "2023-10-16T13:49:40.000Z", - "updated_at": "2023-10-16T13:49:40.000Z" - }, - { - "id": 43, - "public_id": "99999941", - "creator_id": 4, - "content": {}, - "created_at": "2023-10-16T13:49:41.000Z", - "updated_at": "2023-10-16T13:49:41.000Z" - }, - { - "id": 44, - "public_id": "99999942", - "creator_id": 4, - "content": {}, - "created_at": "2023-10-16T13:49:42.000Z", - "updated_at": "2023-10-16T13:49:42.000Z" - }, - { - "id": 45, - "public_id": "99999943", - "creator_id": 4, - "content": {}, - "created_at": "2023-10-16T13:49:43.000Z", - "updated_at": "2023-10-16T13:49:43.000Z" - }, - { - "id": 46, - "public_id": "99999944", - "creator_id": 4, - "content": {}, - "created_at": "2023-10-16T13:49:44.000Z", - "updated_at": "2023-10-16T13:49:44.000Z" - }, - { - "id": 47, - "public_id": "99999945", - "creator_id": 4, - "content": {}, - "created_at": "2023-10-16T13:49:45.000Z", - "updated_at": "2023-10-16T13:49:45.000Z" - }, - { - "id": 48, - "public_id": "99999946", - "creator_id": 4, - "content": {}, - "created_at": "2023-10-16T13:49:46.000Z", - "updated_at": "2023-10-16T13:49:46.000Z" - }, - { - "id": 49, - "public_id": "99999947", - "creator_id": 4, - "content": {}, - "created_at": "2023-10-16T13:49:47.000Z", - "updated_at": "2023-10-16T13:49:47.000Z" - }, - { - "id": 50, - "public_id": "99999948", - "creator_id": 4, - "content": {}, - "created_at": "2023-10-16T13:49:48.000Z", - "updated_at": "2023-10-16T13:49:48.000Z" - }, - { - "id": 51, - "public_id": "99999949", - "creator_id": 4, - "content": {}, - "created_at": "2023-10-16T13:49:49.000Z", - "updated_at": "2023-10-16T13:49:49.000Z" - }, - { - "id": 52, - "public_id": "99999950", - "creator_id": 4, - "content": {}, - "created_at": "2023-10-16T13:49:50.000Z", - "updated_at": "2023-10-16T13:49:50.000Z" - }, - { - "id": 53, - "public_id": "99999902", - "creator_id": 4, - "content": {}, - "created_at": "2023-10-16T13:49:2.000Z", - "updated_at": "2023-10-16T13:49:2.000Z" - }, - { - "id": 54, - "public_id": "f43NU75weU", - "creator_id": 2, - "content": {}, - "created_at": "2023-10-16T13:49:19.000Z", - "updated_at": "2023-10-16T13:49:19.000Z" - }, - { - "id": 55, - "public_id": "Hu8Gsm0sA1", - "creator_id": 2, - "content": {}, - "created_at": "2023-10-16T13:49:19.000Z", - "updated_at": "2023-10-16T13:49:19.000Z" - }, - { - "id": 56, - "public_id": "Uyd8TgkdA0", - "creator_id": 2, - "content": {}, - "created_at": "2023-10-16T13:49:19.000Z", - "updated_at": "2023-10-16T13:49:19.000Z" - } -] diff --git a/src/tests/test-data/user-sessions.json b/src/tests/test-data/user-sessions.json deleted file mode 100644 index 8d816c2ee..000000000 --- a/src/tests/test-data/user-sessions.json +++ /dev/null @@ -1,12 +0,0 @@ -[ - { - "user_id": 4, - "refresh_token": "F5tTF24K9Q", - "refresh_token_expires_at": "2023-11-09 11:23:54+02" - }, - { - "user_id": 1, - "refresh_token": "IqrTkSKmel", - "refresh_token_expires_at": "2025-11-21 19:19:40.911+03" - } -] diff --git a/src/tests/test-data/users.json b/src/tests/test-data/users.json deleted file mode 100644 index 346967c11..000000000 --- a/src/tests/test-data/users.json +++ /dev/null @@ -1,23 +0,0 @@ -[ - { - "id": 1, - "email": "a@a.com", - "name": "Test user 1", - "created_at": "2023-10-16T13:49:19.000Z", - "photo": "" - }, - { - "id": 2, - "email": "elizachi@gmail.com", - "name": "Елизавета", - "created_at": "2023-10-22 19:19:40.892+03", - "photo": "" - }, - { - "id": 4, - "email": "Egoramurin@gmail.com", - "name": "Егор Амурин", - "created_at": "2023-10-22 19:19:40.892+03", - "photo": "" - } -] diff --git a/src/tests/utils/insert-data.ts b/src/tests/utils/insert-data.ts deleted file mode 100644 index 7d15cb7ee..000000000 --- a/src/tests/utils/insert-data.ts +++ /dev/null @@ -1,87 +0,0 @@ -import type SequelizeOrm from '@repository/storage/postgres/orm/index.js'; -import noteRelations from '../test-data/notes-relations.json'; -import users from '../test-data/users.json'; -import userSessions from '../test-data/user-sessions.json'; -import notes from '../test-data/notes.json'; -import noteSettings from '../test-data/notes-settings.json'; -import noteTeams from '../test-data/note-teams.json'; - - -/** - * Fills in the database with users data - * - * @param db - SequelizeOrm instance - */ -async function insertUsers(db: SequelizeOrm): Promise { - for (const user of users) { - await db.connection.query(`INSERT INTO public.users (id, email, name, "created_at") VALUES (${user.id}, '${user.email}', '${user.name}', '${user.created_at}')`); - } -} -/** - * Fills in the database with note teams data - * - * @param db - SequelizeOrm instance - */ -async function insertNoteTeams(db: SequelizeOrm): Promise { - for (const noteTeam of noteTeams) { - await db.connection.query(`INSERT INTO public.note_teams ("note_id", "user_id", "role") VALUES (${noteTeam.note_id}, ${noteTeam.user_id}, '${noteTeam.role}')`); - } -} -/** - * Fills in the database with user sessions - * - * @param db - SequelizeOrm instance - */ -async function insertUserSessions(db: SequelizeOrm): Promise { - for (const userSession of userSessions) { - await db.connection.query(`INSERT INTO public.user_sessions ("user_id", "refresh_token", "refresh_token_expires_at") VALUES (${userSession.user_id}, '${userSession.refresh_token}', '${userSession.refresh_token_expires_at}')`); - } -} -/** - * Fills in the database with notes data - * - * @param db - SequelizeOrm instance - */ -async function insertNotes(db: SequelizeOrm): Promise { - for (const note of notes) { - await db.connection.query(`INSERT INTO public.notes (id, "public_id", "creator_id", "created_at", "updated_at", "content") VALUES (${note.id}, '${note.public_id}', '${note.creator_id}', '${note.created_at}', '${note.updated_at}', '${JSON.stringify(note.content)}')`); - } -} - -/** - * Fills in the database with notes settings data - * - * @param db - SequelizeOrm instance - */ -async function insertNoteSettings(db: SequelizeOrm): Promise { - for (const noteSetting of noteSettings) { - await db.connection.query(`INSERT INTO public.note_settings (id, "note_id", "custom_hostname", "is_public", "invitation_hash") VALUES (${noteSetting.id}, '${noteSetting.note_id}', '${noteSetting.custom_hostname}', ${noteSetting.is_public}, '${noteSetting.invitation_hash}')`); - } -} - -/** - * Fills in the database with notes relationship data - * - * @param db - SequelizeOrm instance - */ -async function insertNoteRelatons(db: SequelizeOrm): Promise { - for (const noteRelation of noteRelations) { - await db.connection.query(`INSERT INTO public.note_relations (id, "note_id", "parent_id") VALUES (${noteRelation.id}, '${noteRelation.note_id}', '${noteRelation.parent_id}')`); - } -} - - -/** - * Fills in the database with test data - * - * @param db - SequelizeOrm instance - */ -export async function insertData(db: SequelizeOrm): Promise { - await insertUsers(db); - await insertUserSessions(db); - await insertNotes(db); - await insertNoteSettings(db); - await insertNoteTeams(db); - await insertNoteRelatons(db); -} - diff --git a/src/tests/utils/setup.ts b/src/tests/utils/setup.ts index d7a79145d..cb5978cc8 100644 --- a/src/tests/utils/setup.ts +++ b/src/tests/utils/setup.ts @@ -2,7 +2,6 @@ import path from 'path'; import type { StartedPostgreSqlContainer } from '@testcontainers/postgresql'; import { PostgreSqlContainer } from '@testcontainers/postgresql'; -import { insertData } from './insert-data.js'; import { initORM, init as initRepositories } from '@repository/index.js'; import { init as initDomainServices } from '@domain/index.js'; import config from '@infrastructure/config/index.js'; @@ -64,7 +63,6 @@ beforeAll(async () => { await api.init(domainServices); await runTenantMigrations(migrationsPath, postgresContainer.getConnectionUri()); - await insertData(orm); global.api = api;