From 9d86d9d2169be0129c66fbd96678c01ddc6f6862 Mon Sep 17 00:00:00 2001 From: Ivan Skvorcov Date: Sun, 21 Jan 2024 15:58:40 +0300 Subject: [PATCH 01/15] DomainError import fix --- src/domain/service/note.ts | 2 +- src/domain/service/noteSettings.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/domain/service/note.ts b/src/domain/service/note.ts index 30f927f2..b4a53ab5 100644 --- a/src/domain/service/note.ts +++ b/src/domain/service/note.ts @@ -1,7 +1,7 @@ import type { Note, NoteInternalId, NotePublicId } from '@domain/entities/note.js'; import type NoteRepository from '@repository/note.repository.js'; import { createPublicId } from '@infrastructure/utils/id.js'; -import { DomainError } from '@domain/entities/DomainError'; +import { DomainError } from '@domain/entities/DomainError.js'; /** * Note service diff --git a/src/domain/service/noteSettings.ts b/src/domain/service/noteSettings.ts index 475194d5..5d6cfacb 100644 --- a/src/domain/service/noteSettings.ts +++ b/src/domain/service/noteSettings.ts @@ -7,7 +7,7 @@ import type { Team, TeamMember, TeamMemberCreationAttributes } from '@domain/ent import { MemberRole } from '@domain/entities/team.js'; import type User from '@domain/entities/user.js'; import { createInvitationHash } from '@infrastructure/utils/invitationHash.js'; -import { DomainError } from '@domain/entities/DomainError'; +import { DomainError } from '@domain/entities/DomainError.js'; /** * Service responsible for Note Settings From 58044a377684881b85b658c5c869cd2155e7ea2a Mon Sep 17 00:00:00 2001 From: Ivan Skvorcov Date: Sun, 21 Jan 2024 23:38:04 +0300 Subject: [PATCH 02/15] New method to get team with aditional info --- src/domain/service/noteSettings.ts | 10 ++++++++ src/presentation/http/router/noteSettings.ts | 12 ++++++++-- .../storage/postgres/orm/sequelize/teams.ts | 23 +++++++++++++++++++ src/repository/team.repository.ts | 10 ++++++++ 4 files changed, 53 insertions(+), 2 deletions(-) diff --git a/src/domain/service/noteSettings.ts b/src/domain/service/noteSettings.ts index 5d6cfacb..6032f98c 100644 --- a/src/domain/service/noteSettings.ts +++ b/src/domain/service/noteSettings.ts @@ -132,6 +132,16 @@ export default class NoteSettingsService { return await this.teamRepository.getByNoteId(noteId); } + /** + * Get all team members by note id with info about users + * + * @param noteId - note id to get all team members + * @returns team with additional info + */ + public async getTeamWithUsersInfoByNoteId(noteId: NoteInternalId): Promise { + return await this.teamRepository.getMembersWithUsersInfoByNoteId(noteId); + } + /** * Remove team member by id * diff --git a/src/presentation/http/router/noteSettings.ts b/src/presentation/http/router/noteSettings.ts index 404895fb..af570d69 100644 --- a/src/presentation/http/router/noteSettings.ts +++ b/src/presentation/http/router/noteSettings.ts @@ -56,7 +56,10 @@ const NoteSettingsRouter: FastifyPluginCallback = (fa Params: { notePublicId: NotePublicId; }, - Reply: NoteSettings + Reply: { + noteSettings: NoteSettings, + team: Team, + } }>('/:notePublicId', { config: { policy: [ @@ -79,6 +82,8 @@ const NoteSettingsRouter: FastifyPluginCallback = (fa const noteSettings = await noteSettingsService.getNoteSettingsByNoteId(noteId); + const team = await noteSettingsService.getTeamWithUsersInfoByNoteId(noteId); + /** * Check if note does not exist */ @@ -86,7 +91,10 @@ const NoteSettingsRouter: FastifyPluginCallback = (fa return reply.notFound('Note settings not found'); } - return reply.send(noteSettings); + return reply.send({ + noteSettings: noteSettings, + team: team, + }); }); /** diff --git a/src/repository/storage/postgres/orm/sequelize/teams.ts b/src/repository/storage/postgres/orm/sequelize/teams.ts index c263b14e..20013f15 100644 --- a/src/repository/storage/postgres/orm/sequelize/teams.ts +++ b/src/repository/storage/postgres/orm/sequelize/teams.ts @@ -206,6 +206,29 @@ export default class TeamsSequelizeStorage { }); } + /** + * Get all team members by note id with info about users + * + * @param noteId - note id to get all team members + * @returns team with additional info + */ + public async getMembersWithUsersInfoById(noteId: NoteInternalId): Promise { + if (!this.userModel) { + throw new Error('User model not initialized'); + } + + return await this.model.findAll({ + where: { noteId }, + attributes: ['id', 'role'], + include: { + model: this.userModel, + as: 'users', + required: true, + attributes: ['id', 'name', 'email', 'photo'], + }, + }); + } + /** * Remove team member by id * diff --git a/src/repository/team.repository.ts b/src/repository/team.repository.ts index da2fd21b..089fe7c4 100644 --- a/src/repository/team.repository.ts +++ b/src/repository/team.repository.ts @@ -63,6 +63,16 @@ export default class TeamRepository { return await this.storage.getMembersByNoteId(noteId); } + /** + * Get all team members by note id with info about users + * + * @param noteId - note id to get all team members + * @returns team with additional info + */ + public async getMembersWithUsersInfoByNoteId(noteId: NoteInternalId): Promise { + return await this.storage.getMembersWithUsersInfoById(noteId); + } + /** * Remove team member by id * From af37b0c9a55561e459ee001b9c5d09fa39cab77b Mon Sep 17 00:00:00 2001 From: Ivan Skvorcov Date: Sun, 21 Jan 2024 23:50:35 +0300 Subject: [PATCH 03/15] Added new test data --- src/tests/test-data/note-teams.json | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/tests/test-data/note-teams.json b/src/tests/test-data/note-teams.json index 2ffb4a63..f051d76b 100644 --- a/src/tests/test-data/note-teams.json +++ b/src/tests/test-data/note-teams.json @@ -4,5 +4,11 @@ "note_id": 1, "user_id": 2, "role": 0 + }, + { + "id": 2, + "note_id": 2, + "user_id": 4, + "role": 1 } ] From 91dea83aeacbaefc92d067930ebb74f401d12a1a Mon Sep 17 00:00:00 2001 From: Ivan Skvorcov Date: Sun, 21 Jan 2024 23:51:30 +0300 Subject: [PATCH 04/15] Tests updated --- src/presentation/http/router/join.test.ts | 2 +- .../http/router/noteSettings.test.ts | 24 +++++++++++++++---- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/src/presentation/http/router/join.test.ts b/src/presentation/http/router/join.test.ts index a086ef00..3809f44e 100644 --- a/src/presentation/http/router/join.test.ts +++ b/src/presentation/http/router/join.test.ts @@ -58,7 +58,7 @@ describe('Join API', () => { expect(response?.json()).toStrictEqual({ result: { - id: 2, + id: 3, userId, noteId: 1, role: 0, diff --git a/src/presentation/http/router/noteSettings.test.ts b/src/presentation/http/router/noteSettings.test.ts index b09df15e..4fda4efa 100644 --- a/src/presentation/http/router/noteSettings.test.ts +++ b/src/presentation/http/router/noteSettings.test.ts @@ -10,11 +10,25 @@ describe('NoteSettings API', () => { const existingNotePublicId = 'Pq1T9vc23Q'; const expectedNoteSettings = { - 'customHostname': 'codex.so', - 'isPublic': true, - 'id': 2, - 'noteId': 2, - 'invitationHash': 'E2zRXv3cp-', + 'noteSettings': { + 'customHostname': 'codex.so', + 'id': 2, + 'invitationHash': 'E2zRXv3cp-', + 'isPublic': true, + 'noteId': 2, + }, + 'team': [ + { + 'id': 2, + 'role': 1, + 'users': { + 'email': 'Egoramurin@gmail.com', + 'id': 4, + 'name': 'Егор Амурин', + 'photo': null, + }, + }, + ], }; const response = await global.api?.fakeRequest({ From 5b30ff31975e7bc4ce3053e5ff45b889e9e6227d Mon Sep 17 00:00:00 2001 From: Ivan Skvorcov Date: Mon, 29 Jan 2024 01:31:42 +0300 Subject: [PATCH 05/15] added interface to team sequelize --- .../storage/postgres/orm/sequelize/noteSettings.ts | 1 + .../storage/postgres/orm/sequelize/teams.ts | 14 +++++++++++--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/repository/storage/postgres/orm/sequelize/noteSettings.ts b/src/repository/storage/postgres/orm/sequelize/noteSettings.ts index 89c44b35..565bb6ed 100644 --- a/src/repository/storage/postgres/orm/sequelize/noteSettings.ts +++ b/src/repository/storage/postgres/orm/sequelize/noteSettings.ts @@ -152,6 +152,7 @@ export default class NoteSettingsSequelizeStorage { where: { noteId: noteId, }, + raw: true, }); if (!settings) { diff --git a/src/repository/storage/postgres/orm/sequelize/teams.ts b/src/repository/storage/postgres/orm/sequelize/teams.ts index b750e169..0096b3bb 100644 --- a/src/repository/storage/postgres/orm/sequelize/teams.ts +++ b/src/repository/storage/postgres/orm/sequelize/teams.ts @@ -7,6 +7,14 @@ import { UserModel } from './user.js'; import { MemberRole } from '@domain/entities/team.js'; import type User from '@domain/entities/user.js'; import type { NoteInternalId } from '@domain/entities/note.js'; +import { DomainError } from '@domain/entities/DomainError.js'; + +interface TeamMemberWithUserInfo extends TeamMember { + /** + * Information about user + */ + users?: User; +} /** @@ -213,9 +221,9 @@ export default class TeamsSequelizeStorage { * @param noteId - note id to get all team members * @returns team with additional info */ - public async getMembersWithUsersInfoById(noteId: NoteInternalId): Promise { + public async getTeamMembersByNoteId(noteId: NoteInternalId): Promise { if (!this.userModel) { - throw new Error('User model not initialized'); + throw new DomainError('User model not initialized'); } return await this.model.findAll({ @@ -227,7 +235,7 @@ export default class TeamsSequelizeStorage { required: true, attributes: ['id', 'name', 'email', 'photo'], }, - }); + }) as TeamMemberWithUserInfo[]; } /** From 4660fcea604ca372b47a99f56d7bca88d538580b Mon Sep 17 00:00:00 2001 From: Ivan Skvorcov Date: Mon, 29 Jan 2024 01:34:23 +0300 Subject: [PATCH 06/15] Team field added to NoteSettings in reply --- .../http/router/noteSettings.test.ts | 22 +++++++++---------- src/presentation/http/router/noteSettings.ts | 22 +++---------------- src/repository/team.repository.ts | 12 +++++++--- 3 files changed, 22 insertions(+), 34 deletions(-) diff --git a/src/presentation/http/router/noteSettings.test.ts b/src/presentation/http/router/noteSettings.test.ts index adc32066..052b6b76 100644 --- a/src/presentation/http/router/noteSettings.test.ts +++ b/src/presentation/http/router/noteSettings.test.ts @@ -10,21 +10,19 @@ describe('NoteSettings API', () => { const existingNotePublicId = 'Pq1T9vc23Q'; const expectedNoteSettings = { - 'noteSettings': { - 'customHostname': 'codex.so', - 'id': 2, - 'invitationHash': 'E2zRXv3cp-', - 'isPublic': true, - 'noteId': 2, - }, + 'customHostname': 'codex.so', + 'id': 2, + 'invitationHash': 'E2zRXv3cp-', + 'isPublic': true, + 'noteId': 2, 'team': [ { 'id': 2, - 'role': 1, - 'users': { - 'email': 'Egoramurin@gmail.com', - 'id': 4, - 'name': 'Егор Амурин', + 'role': 0, + 'user': { + 'email': 'a@a.com', + 'id': 1, + 'name': 'Test user 1', 'photo': null, }, }, diff --git a/src/presentation/http/router/noteSettings.ts b/src/presentation/http/router/noteSettings.ts index 965ecdd8..304892d4 100644 --- a/src/presentation/http/router/noteSettings.ts +++ b/src/presentation/http/router/noteSettings.ts @@ -2,12 +2,11 @@ import type { FastifyPluginCallback } from 'fastify'; import type NoteSettingsService from '@domain/service/noteSettings.js'; import type NoteSettings from '@domain/entities/noteSettings.js'; import type { InvitationHash } from '@domain/entities/noteSettings.js'; -import { isEmpty } from '@infrastructure/utils/empty.js'; import useNoteResolver from '../middlewares/note/useNoteResolver.js'; import type NoteService from '@domain/service/note.js'; import useNoteSettingsResolver from '../middlewares/noteSettings/useNoteSettingsResolver.js'; import type { NotePublicId } from '@domain/entities/note.js'; -import type { Team, MemberRole } from '@domain/entities/team.js'; +import type { Team, MemberRole, TeamMember } from '@domain/entities/team.js'; import type User from '@domain/entities/user.js'; /** @@ -58,10 +57,7 @@ const NoteSettingsRouter: FastifyPluginCallback = (fa Params: { notePublicId: NotePublicId; }, - Reply: { - noteSettings: NoteSettings, - team: Team, - } + Reply: NoteSettings & {team: { id: TeamMember['id'], user?: User, role: MemberRole }[]}, }>('/:notePublicId', { config: { policy: [ @@ -84,19 +80,7 @@ const NoteSettingsRouter: FastifyPluginCallback = (fa const noteSettings = await noteSettingsService.getNoteSettingsByNoteId(noteId); - const team = await noteSettingsService.getTeamWithUsersInfoByNoteId(noteId); - - /** - * Check if note does not exist - */ - if (isEmpty(noteSettings)) { - return reply.notFound('Note settings not found'); - } - - return reply.send({ - noteSettings: noteSettings, - team: team, - }); + return reply.send(noteSettings); }); /** diff --git a/src/repository/team.repository.ts b/src/repository/team.repository.ts index 73cf0a17..b0c539ee 100644 --- a/src/repository/team.repository.ts +++ b/src/repository/team.repository.ts @@ -69,9 +69,15 @@ export default class TeamRepository { * @param noteId - note id to get all team members * @returns team with additional info */ - public async getMembersWithUsersInfoByNoteId(noteId: NoteInternalId): Promise { - return await this.storage.getMembersWithUsersInfoById(noteId); - } + public async getTeamMembersByNoteId(noteId: NoteInternalId): Promise<{ id: TeamMember['id'], user?: User, role: MemberRole }[]> { + const team = await this.storage.getTeamMembersByNoteId(noteId); + + return team.map(( + { users, id, role }) => + ({ id: id, + user: users, + role: role })); + }; /** * Remove team member by id From 41941de90541837b49bdf7f52405a2abdcde68b2 Mon Sep 17 00:00:00 2001 From: Ivan Skvorcov Date: Mon, 29 Jan 2024 01:34:43 +0300 Subject: [PATCH 07/15] Test data fix --- src/tests/test-data/note-teams.json | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/tests/test-data/note-teams.json b/src/tests/test-data/note-teams.json index 99e26aea..b4d3c257 100644 --- a/src/tests/test-data/note-teams.json +++ b/src/tests/test-data/note-teams.json @@ -7,11 +7,6 @@ }, { "id": 2, - "note_id": 2, - "user_id": 4, - "role": 1 - }, - { "id": 2, "note_id": 2, "user_id": 1, "role": 0 From 29f03a0163d1d5497baf19923cfce58ec6dbd9b8 Mon Sep 17 00:00:00 2001 From: Ivan Skvorcov Date: Mon, 29 Jan 2024 01:35:25 +0300 Subject: [PATCH 08/15] updated NoteSettings service --- src/domain/service/noteSettings.ts | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/src/domain/service/noteSettings.ts b/src/domain/service/noteSettings.ts index 6185da1c..026c1821 100644 --- a/src/domain/service/noteSettings.ts +++ b/src/domain/service/noteSettings.ts @@ -65,18 +65,23 @@ export default class NoteSettingsService { } /** - * Returns settings for a note with passed id + * Returns settings for a note with all team members * * @param id - note internal id */ - public async getNoteSettingsByNoteId(id: NoteInternalId): Promise { - const settings = await this.noteSettingsRepository.getNoteSettingsByNoteId(id); + public async getNoteSettingsByNoteId(id: NoteInternalId): Promise { + const noteSettings = await this.noteSettingsRepository.getNoteSettingsByNoteId(id); - if (settings === null) { + if (noteSettings === null) { throw new DomainError(`Note settings not found`); } - return settings; + const team = await this.teamRepository.getTeamMembersByNoteId(id); + + return { + ...noteSettings, + team, + }; } /** @@ -132,16 +137,6 @@ export default class NoteSettingsService { return await this.teamRepository.getByNoteId(noteId); } - /** - * Get all team members by note id with info about users - * - * @param noteId - note id to get all team members - * @returns team with additional info - */ - public async getTeamWithUsersInfoByNoteId(noteId: NoteInternalId): Promise { - return await this.teamRepository.getMembersWithUsersInfoByNoteId(noteId); - } - /** * Remove team member by id * From d12206f73797182d02ffcb8f26d398e0b337a537 Mon Sep 17 00:00:00 2001 From: Ivan Skvorcov Date: Tue, 30 Jan 2024 01:55:44 +0300 Subject: [PATCH 09/15] Team property added to NoteSettings entity --- src/domain/entities/noteSettings.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/domain/entities/noteSettings.ts b/src/domain/entities/noteSettings.ts index 1994c094..2290f2ef 100644 --- a/src/domain/entities/noteSettings.ts +++ b/src/domain/entities/noteSettings.ts @@ -1,3 +1,6 @@ +import type { Team } from './team.js'; + + /** * Invitation hash. It's used to invite users to team */ @@ -31,6 +34,11 @@ export default interface NoteSettings { * Invitation hash */ invitationHash: InvitationHash; + + /** + * Team members + */ + team: Team; } /** From 107c216fe7ad9708b96b789ef261a517128d2d6f Mon Sep 17 00:00:00 2001 From: Ivan Skvorcov Date: Tue, 30 Jan 2024 01:56:16 +0300 Subject: [PATCH 10/15] Changed alias --- .../storage/postgres/orm/sequelize/teams.ts | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/src/repository/storage/postgres/orm/sequelize/teams.ts b/src/repository/storage/postgres/orm/sequelize/teams.ts index 0096b3bb..b49b46c9 100644 --- a/src/repository/storage/postgres/orm/sequelize/teams.ts +++ b/src/repository/storage/postgres/orm/sequelize/teams.ts @@ -9,14 +9,6 @@ import type User from '@domain/entities/user.js'; import type { NoteInternalId } from '@domain/entities/note.js'; import { DomainError } from '@domain/entities/DomainError.js'; -interface TeamMemberWithUserInfo extends TeamMember { - /** - * Information about user - */ - users?: User; -} - - /** * Class representing a teams model in database */ @@ -148,7 +140,7 @@ export default class TeamsSequelizeStorage { */ this.model.belongsTo(model, { foreignKey: 'userId', - as: this.userModel.tableName, + as: 'user', }); } @@ -221,7 +213,7 @@ export default class TeamsSequelizeStorage { * @param noteId - note id to get all team members * @returns team with additional info */ - public async getTeamMembersByNoteId(noteId: NoteInternalId): Promise { + public async getTeamMembersByNoteId(noteId: NoteInternalId): Promise { if (!this.userModel) { throw new DomainError('User model not initialized'); } @@ -231,11 +223,11 @@ export default class TeamsSequelizeStorage { attributes: ['id', 'role'], include: { model: this.userModel, - as: 'users', + as: 'user', required: true, attributes: ['id', 'name', 'email', 'photo'], }, - }) as TeamMemberWithUserInfo[]; + }); } /** From aed6eb32f4620f96ca3068893f68404718af3ba1 Mon Sep 17 00:00:00 2001 From: Ivan Skvorcov Date: Tue, 30 Jan 2024 01:57:41 +0300 Subject: [PATCH 11/15] Removed redundant logic --- src/domain/service/noteSettings.ts | 9 +++------ src/presentation/http/router/noteSettings.ts | 4 ++-- src/repository/team.repository.ts | 10 ++-------- 3 files changed, 7 insertions(+), 16 deletions(-) diff --git a/src/domain/service/noteSettings.ts b/src/domain/service/noteSettings.ts index 026c1821..1541a3a0 100644 --- a/src/domain/service/noteSettings.ts +++ b/src/domain/service/noteSettings.ts @@ -69,19 +69,16 @@ export default class NoteSettingsService { * * @param id - note internal id */ - public async getNoteSettingsByNoteId(id: NoteInternalId): Promise { + public async getNoteSettingsByNoteId(id: NoteInternalId): Promise { const noteSettings = await this.noteSettingsRepository.getNoteSettingsByNoteId(id); if (noteSettings === null) { throw new DomainError(`Note settings not found`); } - const team = await this.teamRepository.getTeamMembersByNoteId(id); + noteSettings.team = await this.teamRepository.getTeamMembersByNoteId(id); - return { - ...noteSettings, - team, - }; + return noteSettings; } /** diff --git a/src/presentation/http/router/noteSettings.ts b/src/presentation/http/router/noteSettings.ts index 304892d4..23c63c0d 100644 --- a/src/presentation/http/router/noteSettings.ts +++ b/src/presentation/http/router/noteSettings.ts @@ -6,7 +6,7 @@ import useNoteResolver from '../middlewares/note/useNoteResolver.js'; import type NoteService from '@domain/service/note.js'; import useNoteSettingsResolver from '../middlewares/noteSettings/useNoteSettingsResolver.js'; import type { NotePublicId } from '@domain/entities/note.js'; -import type { Team, MemberRole, TeamMember } from '@domain/entities/team.js'; +import type { Team, MemberRole } from '@domain/entities/team.js'; import type User from '@domain/entities/user.js'; /** @@ -57,7 +57,7 @@ const NoteSettingsRouter: FastifyPluginCallback = (fa Params: { notePublicId: NotePublicId; }, - Reply: NoteSettings & {team: { id: TeamMember['id'], user?: User, role: MemberRole }[]}, + Reply: NoteSettings, }>('/:notePublicId', { config: { policy: [ diff --git a/src/repository/team.repository.ts b/src/repository/team.repository.ts index b0c539ee..f339db67 100644 --- a/src/repository/team.repository.ts +++ b/src/repository/team.repository.ts @@ -69,14 +69,8 @@ export default class TeamRepository { * @param noteId - note id to get all team members * @returns team with additional info */ - public async getTeamMembersByNoteId(noteId: NoteInternalId): Promise<{ id: TeamMember['id'], user?: User, role: MemberRole }[]> { - const team = await this.storage.getTeamMembersByNoteId(noteId); - - return team.map(( - { users, id, role }) => - ({ id: id, - user: users, - role: role })); + public async getTeamMembersByNoteId(noteId: NoteInternalId): Promise { + return await this.storage.getTeamMembersByNoteId(noteId); }; /** From 3ad0020205d12b0274f86e13b92c8b25c0746a5d Mon Sep 17 00:00:00 2001 From: Ivan Skvorcov Date: Tue, 30 Jan 2024 01:58:44 +0300 Subject: [PATCH 12/15] Updated NoteSettings Schema --- src/domain/entities/noteSettings.ts | 2 +- src/presentation/http/schema/NoteSettings.ts | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/domain/entities/noteSettings.ts b/src/domain/entities/noteSettings.ts index 2290f2ef..cda1bee1 100644 --- a/src/domain/entities/noteSettings.ts +++ b/src/domain/entities/noteSettings.ts @@ -38,7 +38,7 @@ export default interface NoteSettings { /** * Team members */ - team: Team; + team?: Team; } /** diff --git a/src/presentation/http/schema/NoteSettings.ts b/src/presentation/http/schema/NoteSettings.ts index 3e669485..df282273 100644 --- a/src/presentation/http/schema/NoteSettings.ts +++ b/src/presentation/http/schema/NoteSettings.ts @@ -24,5 +24,25 @@ export const NoteSettingsSchema = { maxLength: 10, minLength: 10, }, + team: { + type: 'array', + items: { + type: 'object', + properties: { + id: { + type: 'number', + }, + noteId: { + type: 'number', + }, + userId: { + type: 'number', + }, + role: { + type: 'number', + }, + }, + }, + }, }, }; From e55f92217fb75e8e0916ba50cc805c0dd00b227d Mon Sep 17 00:00:00 2001 From: Ivan Skvorcov Date: Thu, 1 Feb 2024 01:10:48 +0300 Subject: [PATCH 13/15] Updated comments in noteSettings entity --- src/domain/entities/noteSettings.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/domain/entities/noteSettings.ts b/src/domain/entities/noteSettings.ts index cda1bee1..79313548 100644 --- a/src/domain/entities/noteSettings.ts +++ b/src/domain/entities/noteSettings.ts @@ -36,7 +36,7 @@ export default interface NoteSettings { invitationHash: InvitationHash; /** - * Team members + * Team members. Team is empty by default because note creator is not stored in team */ team?: Team; } From 55e9e11d10c13cb9383fadacc20fc64fccaf05bc Mon Sep 17 00:00:00 2001 From: Ivan Skvorcov Date: Thu, 1 Feb 2024 03:00:46 +0300 Subject: [PATCH 14/15] Added test to noteSettings.test --- .../http/router/noteSettings.test.ts | 47 ++++++++++++------- 1 file changed, 31 insertions(+), 16 deletions(-) diff --git a/src/presentation/http/router/noteSettings.test.ts b/src/presentation/http/router/noteSettings.test.ts index af064985..4dcfe3f6 100644 --- a/src/presentation/http/router/noteSettings.test.ts +++ b/src/presentation/http/router/noteSettings.test.ts @@ -6,26 +6,15 @@ import noteSettings from '@tests/test-data/notes-settings.json'; describe('NoteSettings API', () => { describe('GET /note-settings/:notePublicId ', () => { test('Returns note settings by public id with 200 status', async () => { - const existingNotePublicId = 'Pq1T9vc23Q'; + const existingNotePublicId = 'f43NU75weU'; const expectedNoteSettings = { 'customHostname': 'codex.so', - 'id': 3, - 'invitationHash': 'E2zRXv3cp-', + 'id': 54, + 'invitationHash': 'FfAwyaR80C', 'isPublic': true, - 'noteId': 3, - 'team': [ - { - 'id': 2, - 'role': 0, - 'user': { - 'email': 'a@a.com', - 'id': 1, - 'name': 'Test user 1', - 'photo': null, - }, - }, - ], + 'noteId': 54, + 'team': [], }; const response = await global.api?.fakeRequest({ @@ -38,6 +27,32 @@ describe('NoteSettings API', () => { expect(response?.json()).toStrictEqual(expectedNoteSettings); }); + test('Returns team with note settings by public id with 200 status', async () => { + const existingNotePublicId = 'Pq1T9vc23Q'; + + const expectedTeam = [ + { + 'id': 2, + 'role': 0, + 'user': { + 'email': 'a@a.com', + 'id': 1, + 'name': 'Test user 1', + 'photo': null, + }, + }, + ]; + + const response = await global.api?.fakeRequest({ + method: 'GET', + url: `/note-settings/${existingNotePublicId}`, + }); + + expect(response?.statusCode).toBe(200); + + expect(response?.json().team).toStrictEqual(expectedTeam); + }); + test('Returns 404 when note settings with specified note public id do not exist', async () => { const nonexistentId = 'ishvm5qH84'; From 658fc8896037009475f347c91401646171a6e818 Mon Sep 17 00:00:00 2001 From: Ivan Skvorcov Date: Tue, 13 Feb 2024 18:56:09 +0300 Subject: [PATCH 15/15] Removed expectedTeam --- .../http/router/noteSettings.test.ts | 20 +++++++++---------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/src/presentation/http/router/noteSettings.test.ts b/src/presentation/http/router/noteSettings.test.ts index 4dcfe3f6..ab464e82 100644 --- a/src/presentation/http/router/noteSettings.test.ts +++ b/src/presentation/http/router/noteSettings.test.ts @@ -30,7 +30,14 @@ describe('NoteSettings API', () => { test('Returns team with note settings by public id with 200 status', async () => { const existingNotePublicId = 'Pq1T9vc23Q'; - const expectedTeam = [ + const response = await global.api?.fakeRequest({ + method: 'GET', + url: `/note-settings/${existingNotePublicId}`, + }); + + expect(response?.statusCode).toBe(200); + + expect(response?.json().team).toStrictEqual([ { 'id': 2, 'role': 0, @@ -41,16 +48,7 @@ describe('NoteSettings API', () => { 'photo': null, }, }, - ]; - - const response = await global.api?.fakeRequest({ - method: 'GET', - url: `/note-settings/${existingNotePublicId}`, - }); - - expect(response?.statusCode).toBe(200); - - expect(response?.json().team).toStrictEqual(expectedTeam); + ]); }); test('Returns 404 when note settings with specified note public id do not exist', async () => {