Skip to content

Commit

Permalink
test: minor configuration changes
Browse files Browse the repository at this point in the history
  • Loading branch information
tericcabrel committed Jun 9, 2024
1 parent 673ba7e commit a53c069
Show file tree
Hide file tree
Showing 23 changed files with 132 additions and 202 deletions.
3 changes: 2 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"plugin:@typescript-eslint/recommended",
"plugin:prettier/recommended",
"plugin:typescript-sort-keys/recommended",
"plugin:jest/recommended"
"plugin:jest/recommended",
"turbo"
],
"plugins": [
"sort-destructure-keys",
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ jobs:
MYSQL_DATABASE: test
MYSQL_PORT: 3306
DATABASE_URL: mysql:https://root:[email protected]:3306/test
TEST_DATABASE_URL: mysql:https://root:[email protected]:3306/test
CONVERTKIT_API_KEY: api_key
CONVERTKIT_FORM_ID: form_id
outputs:
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
"dotenv-cli": "7.4.2",
"eslint": "8.56.0",
"eslint-config-prettier": "9.1.0",
"eslint-config-turbo": "2.0.3",
"eslint-plugin-import": "2.29.1",
"eslint-plugin-jest": "27.9.0",
"eslint-plugin-prettier": "5.1.3",
Expand Down
2 changes: 1 addition & 1 deletion packages/domain/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"db:seed": "yarn env -- prisma db seed",
"db:test": "zx tests/database.mjs",
"db:test:stop": "docker container kill snipcode-test-db && docker container prune -f",
"test": "NODE_ENV=test yarn db:test && dotenv -e .env.test -- jest"
"test": "NODE_ENV=test yarn db:test && dotenv -e .env.test -- jest --runInBand"
},
"dependencies": {
"@bugsnag/cuid": "3.1.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,14 @@ import { Folder } from '../folder.entity';

describe('Test Create Folder Input', () => {
it('should create a valid folder object', () => {
// GIVEN
const input = new CreateFolderInput({
name: 'blogs',
parentId: 'cl23rzwe5000002czaedc8sll',
userId: 'dm34saxf6111113dabfed9tmm',
});

// WHEN
const folder = input.toFolder();

// THEN
expect(folder).toMatchObject<Folder>({
createdAt: expect.any(Date),
id: expect.any(String),
Expand All @@ -27,44 +24,35 @@ describe('Test Create Folder Input', () => {
});

it('should create the valid folder name', () => {
// GIVEN
const input = new CreateFolderInput({
name: 'blogs',
parentId: 'cl23rzwe5000002czaedc8sll',
userId: 'dm34saxf6111113dabfed9tmm',
});
const expectedFolderName = 'blogs';

// WHEN
// THEN
expect(input.name).toEqual(expectedFolderName);
});

it('should create the valid folder parent id', () => {
// GIVEN
const input = new CreateFolderInput({
name: 'blogs',
parentId: 'cl23rzwe5000002czaedc8sll',
userId: 'dm34saxf6111113dabfed9tmm',
});
const expectedParentId = 'cl23rzwe5000002czaedc8sll';

// WHEN
// THEN
expect(input.parentFolderId).toEqual(expectedParentId);
});

it('should create the valid folder user id', () => {
// GIVEN
const input = new CreateFolderInput({
name: 'blogs',
parentId: 'cl23rzwe5000002czaedc8sll',
userId: 'dm34saxf6111113dabfed9tmm',
});
const expectedUserId = 'dm34saxf6111113dabfed9tmm';

// WHEN
// THEN
expect(input.user).toEqual(expectedUserId);
});
});
6 changes: 0 additions & 6 deletions packages/domain/src/services/folders/utils/folders.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { Folder } from '../folder.entity';

describe('Test folders utilities', () => {
it('should assert the folders contain the root folder', () => {
// GIVEN
const userId = TestHelper.generateTestId();

const rootFolder = TestHelper.createTestFolderInput({ userId }).toFolder();
Expand All @@ -13,26 +12,21 @@ describe('Test folders utilities', () => {

const foldersToDelete: Folder[] = [TestHelper.createTestFolderInput({ userId }).toFolder(), rootFolder];

// WHEN
const isValid = isFoldersContainRoot(foldersToDelete);

// THEN
expect(isValid).toEqual(true);
});

it("should assert the folders doesn't contain the root folder", () => {
// GIVEN
const userId = TestHelper.generateTestId();

const foldersToDelete: Folder[] = [
TestHelper.createTestFolderInput({ userId }).toFolder(),
TestHelper.createTestFolderInput({ userId }).toFolder(),
];

// WHEN
const isValid = isFoldersContainRoot(foldersToDelete);

// THEN
expect(isValid).toEqual(false);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ describe('Newsletter service', () => {
});

test('Add the email address to the newsletter subscribers', async () => {
// GIVEN
const emailToSubscribe = '[email protected]';
const tags = ['snipcode'];
const formId = 'formId';
Expand All @@ -43,17 +42,14 @@ describe('Newsletter service', () => {
},
});

// WHEN
await newsletterService.subscribe(emailToSubscribe, tags);

// THEN
expect(scope.isDone()).toBe(true);

nock.cleanAll();
});

test('Handle HTTP error when the request to add the email address to the newsletter subscribers fails', async () => {
// GIVEN
const emailToSubscribe = '[email protected]';
const tags = ['snipcode'];
const formId = 'formId';
Expand All @@ -68,8 +64,6 @@ describe('Newsletter service', () => {
message: 'Wrong api key provided!',
});

// WHEN
// THEN
const caughtErrorsFormatted = {
data: {
message: 'Wrong api key provided!',
Expand Down
15 changes: 3 additions & 12 deletions packages/domain/src/services/sessions/session.service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,36 +26,29 @@ describe('Test Session Service', function () {
testHelper = new TestHelper(prismaService);
});

it('should create a session', async () => {
// GIVEN
test('Create a session', async () => {
const userId = TestHelper.generateTestId();
const input = TestHelper.createTestSessionInput(userId);

// WHEN
const sessionCreated = await sessionService.create(input);

// THEN
expect(sessionCreated).toMatchObject<Session>(input.toSession());

await testHelper.deleteTestUserSessions(sessionCreated.userId);
});

it('should find a session by token', async () => {
// GIVEN
test('Retrieve a session by the token attached to it', async () => {
const userId = TestHelper.generateTestId();
const session = await testHelper.createTestSession({ userId });

// WHEN
const sessionFound = await sessionService.findByToken(session.token);

// THEN
expect(session).toEqual(sessionFound);

await testHelper.deleteTestUserSessions(session.userId);
});

it('should delete all session of a user', async () => {
// GIVEN
test('Delete all sessions of a user', async () => {
const userId = TestHelper.generateTestId();

const sessionsCreated = await Promise.all([
Expand All @@ -64,10 +57,8 @@ describe('Test Session Service', function () {
testHelper.createTestSession({ userId }),
]);

// WHEN
await sessionService.deleteUserSessions(userId);

// THEN
const userSessions = await Promise.all(sessionsCreated.map(({ token }) => sessionService.findByToken(token)));

expect(userSessions.every((session) => !session)).toBe(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ describe('Test Create Snippet Input', () => {
const folderId = TestHelper.generateTestId();
const userId = TestHelper.generateTestId();

// GIVEN
const input = new CreateSnippetInput({
content: 'import React from "react";\n\nexport const App = () => {\n\n\treturn(\n\t\t<div>Hello</div>\n\t);\n};',
contentHighlighted:
Expand All @@ -22,10 +21,8 @@ describe('Test Create Snippet Input', () => {
visibility: 'public',
});

// WHEN
const folder = input.toSnippet();

// THEN
expect(folder).toMatchObject<Snippet>({
content: 'import React from "react";\n\nexport const App = () => {\n\n\treturn(\n\t\t<div>Hello</div>\n\t);\n};',
contentHtml:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,11 @@ describe('Test Delete Snippet Input', () => {
const snippetId = TestHelper.generateTestId();
const userId = TestHelper.generateTestId();

// GIVEN
const input = new DeleteSnippetInput({
creatorId: userId,
snippetId,
});

// WHEN
// THEN
expect(input.snippetId).toEqual(snippetId);
expect(input.creatorId).toEqual(userId);
});
Expand Down
Loading

0 comments on commit a53c069

Please sign in to comment.