Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move team rights test data to a separate file #218

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
109 changes: 13 additions & 96 deletions src/presentation/http/router/note.test.ts
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

readability decreased. I think it would have sense if the logic will be moved to the util as well. Like creating a user, adding a role, etc

Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { MemberRole } from '@domain/entities/team.js';
import { describe, test, expect, beforeEach } from 'vitest';
import type User from '@domain/entities/user.js';
import { memberRight } from '@tests/utils/team-rights';

describe('Note API', () => {
beforeEach(async () => {
Expand Down Expand Up @@ -243,39 +244,11 @@ describe('Note API', () => {
});

describe('PATCH note/:notePublicId ', () => {
test.each([
/** Returns 200 if user is team member with a Write role */
{
role: MemberRole.Write,
isAuthorized: true,
expectedStatusCode: 200,
},
test.each(memberRight)
('Patch note by public id', async ({ testContext }) => {
/** Get data from context */
const { role, isAuthorized, expectedStatusCode, expectedMessage } = testContext;

/** Returns 403 if user is team member with a Read role */
{
role: MemberRole.Read,
isAuthorized: true,
expectedStatusCode: 403,
expectedMessage: 'Permission denied',
},

/** Returns 403 if user is not in the team */
{
role: null,
isAuthorized: true,
expectedStatusCode: 403,
expectedMessage: 'Permission denied',
},

/** Returns 401 if user is not authorized */
{
role: null,
isAuthorized: false,
expectedStatusCode: 401,
expectedMessage: 'You must be authenticated to access this resource',
},
])
('Patch note by public id', async ({ role, isAuthorized, expectedStatusCode, expectedMessage }) => {
/** Only if user has a Write role, he can edit the note */
const canEdit = role === MemberRole.Write;

Expand Down Expand Up @@ -459,39 +432,11 @@ describe('Note API', () => {
});

describe('DELETE /note/:notePublicId', () => {
test.each([
/** Returns 200 if user is team member with a Write role */
{
role: MemberRole.Write,
isAuthorized: true,
expectedStatusCode: 200,
},

/** Returns 403 if user is team member with a Read role */
{
role: MemberRole.Read,
isAuthorized: true,
expectedStatusCode: 403,
expectedMessage: 'Permission denied',
},

/** Returns 403 if user is not in the team */
{
role: null,
isAuthorized: true,
expectedStatusCode: 403,
expectedMessage: 'Permission denied',
},
test.each(memberRight)
('Delete note by public id', async ({ testContext }) => {
/** Get data from context */
const { role, isAuthorized, expectedStatusCode, expectedMessage } = testContext;

/** Returns 401 if user is not authorized */
{
role: null,
isAuthorized: false,
expectedStatusCode: 401,
expectedMessage: 'You must be authenticated to access this resource',
},
])
('Delete note by public id', async ({ role, isAuthorized, expectedStatusCode, expectedMessage }) => {
/** Create test user - creator of note */
const creator = await global.db.insertUser();

Expand Down Expand Up @@ -674,39 +619,11 @@ describe('Note API', () => {

accessToken = global.auth(user.id);
});
test.each([
/** Returns 200 if user is team member with a Write role */
{
role: MemberRole.Write,
isAuthorized: true,
expectedStatusCode: 200,
},
test.each(memberRight)
('Unlink any parent from note by it\'s public id', async ({ testContext }) => {
/** Get data from context */
const { role, isAuthorized, expectedStatusCode, expectedMessage } = testContext;

/** Returns 403 if user is team member with a Read role */
{
role: MemberRole.Read,
isAuthorized: true,
expectedStatusCode: 403,
expectedMessage: 'Permission denied',
},

/** Returns 403 if user is not in the team */
{
role: null,
isAuthorized: true,
expectedStatusCode: 403,
expectedMessage: 'Permission denied',
},

/** Returns 401 if user is not authorized */
{
role: null,
isAuthorized: false,
expectedStatusCode: 401,
expectedMessage: 'You must be authenticated to access this resource',
},
])
('Unlink any parent from note by it\'s public id', async ({ role, isAuthorized, expectedStatusCode, expectedMessage }) => {
/* Create second user, who will be the creator of the note */
const creator = await global.db.insertUser();

Expand Down
Loading
Loading