Skip to content

Commit

Permalink
Merge pull request #196 from codex-team/change-db-helpers-parameters-…
Browse files Browse the repository at this point in the history
…to-optional

chore(tests): user.name, user.email, note.publicId parametes in database helpers are optional
  • Loading branch information
e11sy authored Feb 24, 2024
2 parents 1a86ef8 + 76f8cd7 commit 958ecbe
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 67 deletions.
12 changes: 2 additions & 10 deletions src/presentation/http/router/join.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,11 @@ describe('Join API', () => {
await global.db.truncateTables();

/** create test user */
const user = await global.db.insertUser({
email: 'test@codexmail.com',
name: 'CodeX',
});
const user = await global.db.insertUser();

/** create test note for created user */
const note = await global.db.insertNote({
creatorId: user.id,
publicId: 'TJmEb89e0l',
});

/** create test note-settings for created note */
Expand Down Expand Up @@ -87,16 +83,12 @@ describe('Join API', () => {
await global.db.truncateTables();

/** create test user */
const user = await global.db.insertUser({
email: 'test@codexmail.com',
name: 'CodeX',
});
const user = await global.db.insertUser();


/** create test note for created user */
const note = await global.db.insertNote({
creatorId: user.id,
publicId: 'TJmEb89e0l',
});

/** create test note-settings for created note */
Expand Down
80 changes: 37 additions & 43 deletions src/presentation/http/router/noteSettings.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ describe('NoteSettings API', () => {
});

test('Returns "team" along with the note settings if the note contains a team', async () => {
const existingNotePublicId = 'Pq1T9vc23Q';

/**
* truncate all tables, which are needed
* restart autoincrement sequences for data to start with id 1
Expand All @@ -46,7 +44,6 @@ describe('NoteSettings API', () => {
/** create test note for created user */
const note = await global.db.insertNote({
creatorId: creator.id,
publicId: existingNotePublicId,
});

/** create test note settings for created note */
Expand All @@ -64,7 +61,7 @@ describe('NoteSettings API', () => {

const response = await global.api?.fakeRequest({
method: 'GET',
url: `/note-settings/${existingNotePublicId}`,
url: `/note-settings/${note.publicId}`,
});

expect(response?.statusCode).toBe(200);
Expand Down Expand Up @@ -135,15 +132,11 @@ describe('NoteSettings API', () => {
await global.db.truncateTables();

/** create test user */
const user = await global.db.insertUser({
email: 'a@a.com',
name: 'Test user 1',
});
const user = await global.db.insertUser();

/** create test note for created user */
const note = await global.db.insertNote({
creatorId: user.id,
publicId: 'Pq1T9vc23Q',
});

/** create test note settings for created note */
Expand All @@ -154,7 +147,7 @@ describe('NoteSettings API', () => {

const response = await global.api?.fakeRequest({
method: 'GET',
url: `/note-settings/Pq1T9vc23Q`,
url: `/note-settings/${note.publicId}`,
});

expect(response?.statusCode).toBe(403);
Expand Down Expand Up @@ -186,7 +179,6 @@ describe('NoteSettings API', () => {
/** create test note for created user */
const note = await global.db.insertNote({
creatorId: creator.id,
publicId: 'Pq1T9vc23Q',
});

/** create note settings for created note */
Expand All @@ -202,7 +194,7 @@ describe('NoteSettings API', () => {
headers: {
authorization: `Bearer ${accessToken}`,
},
url: `/note-settings/Pq1T9vc23Q`,
url: `/note-settings/${note.publicId}`,
});

expect(response?.statusCode).toBe(403);
Expand Down Expand Up @@ -235,7 +227,6 @@ describe('NoteSettings API', () => {
/** create test note for created user */
const note = await global.db.insertNote({
creatorId: creator.id,
publicId: 'Pq1T9vc23Q',
});

/** create test note settings for created note */
Expand All @@ -258,7 +249,7 @@ describe('NoteSettings API', () => {
headers: {
authorization: `Bearer ${accessToken}`,
},
url: `/note-settings/Pq1T9vc23Q/team`,
url: `/note-settings/${note.publicId}/team`,
});

expect(response?.statusCode).toBe(200);
Expand All @@ -271,11 +262,17 @@ describe('NoteSettings API', () => {
});

test('Returns status 401 when the user is not authorized', async () => {
const correctID = 'Pq1T9vc23Q';
await global.db.truncateTables();

const user = await global.db.insertUser();

const note = await global.db.insertNote({
creatorId: user.id,
});

const response = await global.api?.fakeRequest({
method: 'GET',
url: `/note-settings/${correctID}/team`,
url: `/note-settings/${note.publicId}/team`,
});

expect(response?.statusCode).toBe(401);
Expand Down Expand Up @@ -335,15 +332,11 @@ describe('NoteSettings API', () => {
await global.db.truncateTables();

/** create test user */
const user = await global.db.insertUser({
email: 'a@a.com',
name: 'Test user 1',
});
const user = await global.db.insertUser();

/** create test note for created user */
const note = await global.db.insertNote({
creatorId: user.id,
publicId: 'Pq1T9vc23Q',
});

/** create test note settings for created note */
Expand All @@ -359,7 +352,7 @@ describe('NoteSettings API', () => {
headers: {
authorization: `Bearer ${accessToken}`,
},
url: `/note-settings/Pq1T9vc23Q`,
url: `/note-settings/${note.publicId}`,
body: {
'isPublic': false,
},
Expand All @@ -374,11 +367,17 @@ describe('NoteSettings API', () => {
});

test('Returns status 401 when the user is not authorized', async () => {
const correctID = 'Pq1T9vc23Q';
await global.db.truncateTables();

const user = await global.db.insertUser();

const note = await global.db.insertNote({
creatorId: user.id,
});

const response = await global.api?.fakeRequest({
method: 'PATCH',
url: `/note-settings/${correctID}`,
url: `/note-settings/${note.publicId}`,
body: {
'isPublic': false,
},
Expand Down Expand Up @@ -432,11 +431,17 @@ describe('NoteSettings API', () => {

describe('PATCH /note-settings/:notePublicId/invitation-hash ', () => {
test('Returns status 401 when the user is not authorized', async () => {
const correctID = 'Pq1T9vc23Q';
await global.db.truncateTables();

const user = await global.db.insertUser();

const note = await global.db.insertNote({
creatorId: user.id,
});

const response = await global.api?.fakeRequest({
method: 'PATCH',
url: `/note-settings/${correctID}/invitation-hash`,
url: `/note-settings/${note.publicId}/invitation-hash`,
});

expect(response?.statusCode).toBe(401);
Expand All @@ -454,22 +459,17 @@ describe('NoteSettings API', () => {
await global.db.truncateTables();

/** create test user */
const creator = await global.db.insertUser({
email: 'a@a.com',
name: 'Test user 1',
});
const creator = await global.db.insertUser();

/** create test note for created user */
const note = await global.db.insertNote({
creatorId: creator.id,
publicId: 'Pq1T9vc23Q',
});

/** create test note settings for created note */
const noteSettings = await global.db.insertNoteSetting({
noteId: note.id,
isPublic: true,
invitationHash: 'Hzh2hy4igf',
});

const accessToken = global.auth(creator.id);
Expand All @@ -479,7 +479,7 @@ describe('NoteSettings API', () => {
headers: {
authorization: `Bearer ${accessToken}`,
},
url: `/note-settings/Pq1T9vc23Q/invitation-hash`,
url: `/note-settings/${note.publicId}/invitation-hash`,
});

expect(response?.statusCode).toBe(200);
Expand Down Expand Up @@ -555,7 +555,6 @@ describe('NoteSettings API', () => {
/** create test note for created user */
const note = await global.db.insertNote({
creatorId: creator.id,
publicId: 'Pq1T9vc23Q',
});

await global.db.insertNoteTeam({
Expand All @@ -572,7 +571,7 @@ describe('NoteSettings API', () => {
headers: {
authorization: `Bearer ${accessToken}`,
},
url: '/note-settings/Pq1T9vc23Q/team',
url: `/note-settings/${note.publicId}/team`,
body: {
userId: randomTeamMember.id,
newRole: 1,
Expand All @@ -587,7 +586,7 @@ describe('NoteSettings API', () => {
headers: {
authorization: `Bearer ${accessToken}`,
},
url: '/note-settings/Pq1T9vc23Q/team',
url: `/note-settings/${note.publicId}/team`,
});

expect(team?.json()).toMatchObject([
Expand Down Expand Up @@ -622,7 +621,6 @@ describe('NoteSettings API', () => {
/** create test note for created user */
const note = await global.db.insertNote({
creatorId: creator.id,
publicId: 'Pq1T9vc23Q',
});

await global.db.insertNoteTeam({
Expand All @@ -639,7 +637,7 @@ describe('NoteSettings API', () => {
headers: {
authorization: `Bearer ${accessToken}`,
},
url: '/note-settings/Pq1T9vc23Q/team',
url: `/note-settings/${note.publicId}/team`,
body: {
userId: randomTeamMember.id,
newRole: 1,
Expand All @@ -660,15 +658,11 @@ describe('NoteSettings API', () => {
await global.db.truncateTables();

/** create test user */
const user = await global.db.insertUser({
email: 'test@codexmail.com',
name: 'CodeX',
});
const user = await global.db.insertUser();

/** create test note for created user */
const note = await global.db.insertNote({
creatorId: user.id,
publicId: '73NdxFZ4k7',
});

const accessToken = await global.auth(user.id);
Expand Down
Loading

0 comments on commit 958ecbe

Please sign in to comment.