Skip to content

Commit

Permalink
#2770-added test
Browse files Browse the repository at this point in the history
  • Loading branch information
caiodasilva2005 committed Sep 20, 2024
1 parent d04f762 commit c2cb306
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 1 deletion.
27 changes: 26 additions & 1 deletion src/backend/tests/test-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@ import prisma from '../src/prisma/prisma';
import { dbSeedAllUsers } from '../src/prisma/seed-data/users.seed';
import TeamsService from '../src/services/teams.services';
import ReimbursementRequestService from '../src/services/reimbursement-requests.services';
import { ClubAccount, RoleEnum } from 'shared';
import { ClubAccount, RoleEnum, TaskPriority, TaskStatus } from 'shared';
import { batmanAppAdmin, batmanScheduleSettings, batmanSecureSettings, batmanSettings } from './test-data/users.test-data';
import { getWorkPackageTemplateQueryArgs } from '../src/prisma-query-args/work-package-template.query-args';
import DesignReviewsService from '../src/services/design-reviews.services';
import TasksService from '../src/services/tasks.services';

export interface CreateTestUserParams {
firstName: string;
Expand Down Expand Up @@ -414,3 +415,27 @@ export const createTestDesignReview = async () => {
const orgId = organization.organizationId;
return { dr, organization, orgId };
};

export const createTestTask = async (user: User, organization?: Organization) => {

Check failure on line 419 in src/backend/tests/test-utils.ts

View workflow job for this annotation

GitHub Actions / build

'user' is declared but its value is never read.
if (!organization) organization = await createTestOrganization();
const orgId = organization.organizationId;
const testBatman = await createTestUser(batmanAppAdmin, orgId);
const task = await TasksService.createTask(
testBatman,
{
carNumber: 0,
projectNumber: 0,
workPackageNumber: 0
},
'Test task',
'Test',
new Date(),
TaskPriority.High,
TaskStatus.IN_PROGRESS,
[testBatman.userId],
organization
);

if (!task) throw new Error('Failed to create design review');
return { task, organization, orgId };
};
28 changes: 28 additions & 0 deletions src/backend/tests/unmocked/users.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { Organization } from '@prisma/client';
import { createTestOrganization, createTestTask, createTestUser, resetUsers } from '../test-utils';
import { batmanAppAdmin } from '../test-data/users.test-data';
import UsersService from '../../src/services/users.services';

describe('User Tests', () => {
let orgId: string;
let organization: Organization;
beforeEach(async () => {
organization = await createTestOrganization();
orgId = organization.organizationId;
});

afterEach(async () => {
await resetUsers();
});

describe('Get Users Tasks', () => {
it("Succeeds and gets user's assigned tasks", async () => {
const testBatman = await createTestUser(batmanAppAdmin, orgId);
const { task } = await createTestTask(testBatman, organization);

const userTasks = await UsersService.getUserTasks(testBatman.userId, organization);

expect(userTasks).toStrictEqual([task]);
});
});
});

0 comments on commit c2cb306

Please sign in to comment.