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

test(backend): add integration tests on the backend #69

Merged
merged 6 commits into from
Jun 9, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
test(backend): more integration tests on folder
  • Loading branch information
tericcabrel committed Jun 9, 2024
commit 599373c6f710f52bf82ca1c903d264345c875d3a
119 changes: 114 additions & 5 deletions apps/backend/src/features/folders/graphql/folder.integration.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { TestServer, startTestServer } from '../../../utils/tests/server';

const graphqlEndpoint = '/graphql';

describe('Test Folder', () => {
describe('Test Folder Feature', () => {
let server: TestServer;
let testHelper: TestHelper;

Expand Down Expand Up @@ -50,7 +50,7 @@ describe('Test Folder', () => {
const [error] = response.body.errors;

expect(error.extensions.code).toEqual('FOLDER_NOT_FOUND');
expect(error.message).toEqual('The folder with the id non-existent-folder-id not found');
expect(error.message).toEqual('The folder with the id "non-existent-folder-id" not found');
});

test('Fail to create a folder when a folder with the same name already exists in the parent folder', async () => {
Expand Down Expand Up @@ -88,8 +88,7 @@ describe('Test Folder', () => {
expect(error.message).toEqual('A folder named "My First Folder" already exists');
});

// eslint-disable-next-line jest/no-disabled-tests
test.skip("Fail to create a folder when the parent folder doesn't belong to the authenticated user", async () => {
test("Fail to create a folder when the parent folder doesn't belong to the authenticated user", async () => {
const { authToken } = await testHelper.createAuthenticatedUser({});
const { user: user2 } = await testHelper.createAuthenticatedUser({});

Expand All @@ -116,7 +115,7 @@ describe('Test Folder', () => {

const [error] = response.body.errors;

expect(error.extensions.code).toEqual('FOLDER_NOT_BELONG_TO_USER');
expect(error.extensions.code).toEqual('FOLDER_NOT_BELONGING_TO_USER');
expect(error.message).toEqual(
`The folder with the id ${user2.rootFolderId} does not belong to the authenticated user`,
);
Expand Down Expand Up @@ -172,4 +171,114 @@ describe('Test Folder', () => {
user: { id: user.id },
});
});

test('Display the directory of a user', async () => {
const { authToken, user } = await testHelper.createAuthenticatedUser({});
const blogFolderId = await testHelper.createFolder(authToken, {
name: 'Blog',
parentId: user.rootFolderId,
});

const blogPostFolderId = await testHelper.createFolder(authToken, {
name: 'Blog post 1',
parentId: blogFolderId,
});

const codingFolderId = await testHelper.createFolder(authToken, {
name: 'Coding',
parentId: user.rootFolderId,
});

const snippetId = await testHelper.createSnippet(authToken, {
folderId: user.rootFolderId,
name: 'My first snippet',
});

const blogSnippetId = await testHelper.createSnippet(authToken, {
folderId: blogFolderId,
name: 'auth.ts',
});

const query = `
query ListDirectory($folderId: String!) {
listDirectory(folderId: $folderId) {
folders {
id
name
}
paths {
id
name
}
snippets {
id
name
}
}
}
`;

const variables = {
folderId: user.rootFolderId,
};

const response = await request(server.app.getHttpServer())
.post(graphqlEndpoint)
.set('Authorization', authToken)
.send({ query, variables })
.expect(200);

const { listDirectory } = response.body.data;

expect(listDirectory).toMatchObject({
folders: [
{
id: blogFolderId,
name: 'Blog',
},
{
id: codingFolderId,
name: 'Coding',
},
],
paths: [],
snippets: [
{
id: snippetId,
name: 'My first snippet',
},
],
});

const subFolderVariables = {
folderId: blogFolderId,
};

const subFolderResponse = await request(server.app.getHttpServer())
.post(graphqlEndpoint)
.set('Authorization', authToken)
.send({ query, variables: subFolderVariables })
.expect(200);

expect(subFolderResponse.body.data.listDirectory).toMatchObject({
folders: [
{
id: blogPostFolderId,
name: 'Blog post 1',
},
],
paths: [
{
id: blogFolderId,
name: 'Blog',
},
],
snippets: [
{
id: blogSnippetId,
name: 'auth.ts',
},
],
});
});
});
Loading