Skip to content

Commit

Permalink
chore: fixed corrupt test file
Browse files Browse the repository at this point in the history
  • Loading branch information
Goldziher committed Oct 21, 2023
1 parent 0c345b2 commit c2be983
Show file tree
Hide file tree
Showing 5 changed files with 557 additions and 3 deletions.
2 changes: 1 addition & 1 deletion frontend/tests/api/applications-api.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
import { HttpMethod } from '@/constants';
import { ApplicationAnalytics } from '@/types';

describe('applications', () => {
describe('applications API tests', () => {
describe('handleCreateApplication', () => {
it('returns an application', async () => {
const project = await ProjectFactory.build();
Expand Down
151 changes: 151 additions & 0 deletions frontend/tests/api/project-users-api.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
import { ProjectFactory, ProjectUserAccountFactory } from 'tests/factories';
import { mockFetch } from 'tests/mocks';

import {
handleAddUserToProject,
handleRemoveUserFromProject,
handleRetrieveProjectUsers,
handleUpdateUserToPermission,
} from '@/api';
import { HttpMethod } from '@/constants';

describe('project users API tests', () => {
const bearerToken = 'Bearer test_token';

describe('handleRetrieveProjectUsers', () => {
it('returns a list of project users', async () => {
const project = await ProjectFactory.build();
const userAccounts = await ProjectUserAccountFactory.batch(2);

mockFetch.mockResolvedValueOnce({
ok: true,
json: () => Promise.resolve(userAccounts),
});

const data = await handleRetrieveProjectUsers({
projectId: project.id,
});

expect(data).toEqual(userAccounts);
expect(mockFetch).toHaveBeenCalledWith(
new URL(
`http://www.example.com/v1/projects/${project.id}/users/`,
),
{
headers: {
'Authorization': bearerToken,
'Content-Type': 'application/json',
'X-Request-Id': expect.any(String),
},
method: HttpMethod.Get,
},
);
});
});
describe('handleAddUserToProject', () => {
it('returns a project user', async () => {
const project = await ProjectFactory.build();
const userAccount = await ProjectUserAccountFactory.build();

mockFetch.mockResolvedValueOnce({
ok: true,
json: () => Promise.resolve(userAccount),
});

const body = {
email: userAccount.email,
permission: userAccount.permission,
};

const data = await handleAddUserToProject({
projectId: project.id,
data: body,
});

expect(data).toEqual(userAccount);
expect(mockFetch).toHaveBeenCalledWith(
new URL(
`http://www.example.com/v1/projects/${project.id}/users/`,
),
{
headers: {
'Authorization': bearerToken,
'Content-Type': 'application/json',
'X-Request-Id': expect.any(String),
},
method: HttpMethod.Post,
body: JSON.stringify(body),
},
);
});
});
describe('handleUpdateUserToPermission', () => {
it('returns a project user', async () => {
const project = await ProjectFactory.build();
const userAccount = await ProjectUserAccountFactory.build();

mockFetch.mockResolvedValueOnce({
ok: true,
json: () => Promise.resolve(userAccount),
});

const body = {
userId: userAccount.id,
permission: userAccount.permission,
};

const data = await handleUpdateUserToPermission({
projectId: project.id,
data: body,
});

expect(data).toEqual(userAccount);
expect(mockFetch).toHaveBeenCalledWith(
new URL(
`http://www.example.com/v1/projects/${project.id}/users/${userAccount.id}/`,
),
{
headers: {
'Authorization': bearerToken,
'Content-Type': 'application/json',
'X-Request-Id': expect.any(String),
},
method: HttpMethod.Patch,
body: JSON.stringify(body),
},
);
});
});
describe('handleDeleteProjectUser', () => {
it('returns undefined for delete project user api', async () => {
const project = await ProjectFactory.build();
const userAccount = await ProjectUserAccountFactory.build();

mockFetch.mockResolvedValueOnce({
ok: true,
json: () => Promise.resolve(),
});

// eslint-disable-next-line @typescript-eslint/no-confusing-void-expression
const data = await handleRemoveUserFromProject({
projectId: project.id,
userId: userAccount.id,
});

expect(data).toBeUndefined();
expect(mockFetch).toHaveBeenCalledWith(
new URL(
`http://www.example.com/v1/projects/${project.id}/users/${userAccount.id}/`,
),
{
headers: {
'Authorization': bearerToken,
'Content-Type': 'application/json',
'X-Request-Id': expect.any(String),
},
method: HttpMethod.Delete,
},
);
});
});
});
4 changes: 2 additions & 2 deletions frontend/tests/api/projects-api.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable @typescript-eslint/no-confusing-void-expression */
import { ProjectFactory } from 'tests/factories';
import { mockFetch } from 'tests/mocks';

Expand All @@ -12,7 +11,7 @@ import {
import { HttpMethod } from '@/constants';
import { ProjectAnalytics } from '@/types';

describe('Projects', () => {
describe('projects API tests', () => {
describe('handleCreateProject', () => {
it('returns a project', async () => {
const project = await ProjectFactory.build();
Expand Down Expand Up @@ -108,6 +107,7 @@ describe('Projects', () => {
ok: true,
json: () => Promise.resolve(),
});
// eslint-disable-next-line @typescript-eslint/no-confusing-void-expression
const data = await handleDeleteProject({
projectId: project.id,
});
Expand Down
Loading

0 comments on commit c2be983

Please sign in to comment.