Skip to content

Commit

Permalink
feat(jobs): implemented user job folders feature wip
Browse files Browse the repository at this point in the history
  • Loading branch information
AndySakov committed Mar 11, 2024
1 parent d69b90f commit 45dde52
Show file tree
Hide file tree
Showing 14 changed files with 1,010 additions and 16 deletions.
24 changes: 24 additions & 0 deletions src/jobs/dto/create-job-folder.input.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { ApiProperty, ApiPropertyOptional } from "@nestjs/swagger";
import {
IsArray,
IsBoolean,
IsNotEmpty,
IsOptional,
IsString,
} from "class-validator";

export class CreateJobFolderInput {
@ApiProperty()
@IsNotEmpty()
@IsString()
name: string;

@ApiProperty()
@IsArray()
jobs: string[];

@ApiPropertyOptional()
@IsOptional()
@IsBoolean()
isPublic: boolean | null;
}
4 changes: 4 additions & 0 deletions src/jobs/dto/update-job-folder.input.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { PartialType } from "@nestjs/mapped-types";
import { CreateJobFolderInput } from "./create-job-folder.input";

export class UpdateJobFolderInput extends PartialType(CreateJobFolderInput) {}
164 changes: 164 additions & 0 deletions src/jobs/jobs.controller.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
ProjectWithRelations,
data,
DateRange,
JobpostFolder,
} from "src/shared/types";
import { Integer } from "neo4j-driver";
import {
Expand Down Expand Up @@ -47,13 +48,17 @@ import { OrganizationsService } from "src/organizations/organizations.service";
import { MailService } from "src/mail/mail.service";
import { addWeeks, subWeeks } from "date-fns";
import { randomUUID } from "crypto";
import { UserService } from "src/user/user.service";

describe("JobsController", () => {
let controller: JobsController;
let models: ModelService;
let authService: AuthService;
let userService: UserService;
let httpService: HttpService;

let jobFolderId: string;

const logger = new CustomLogger(`${JobsController.name}TestSuite`);

const projectHasArrayPropsDuplication = (
Expand Down Expand Up @@ -197,6 +202,7 @@ describe("JobsController", () => {
ProfileService,
OrganizationsService,
MailService,
UserService,
],
}).compile();

Expand All @@ -205,6 +211,7 @@ describe("JobsController", () => {
await models.onModuleInit();
controller = module.get<JobsController>(JobsController);
authService = module.get<AuthService>(AuthService);
userService = module.get<UserService>(UserService);
httpService = module.get<HttpService>(HttpService);
}, REALLY_LONG_TIME);

Expand Down Expand Up @@ -603,6 +610,163 @@ describe("JobsController", () => {
REALLY_LONG_TIME,
);

it(
"should create a job folder for a user",
async () => {
const req: Partial<Request> = {};
const res: Partial<Response> = {};

jest.spyOn(authService, "getSession").mockImplementation(async () => ({
address: EPHEMERAL_TEST_WALLET,
destroy: async (): Promise<void> => {
logger.log("session destroyed");
},
save: async (): Promise<void> => {
logger.log("session saved");
},
}));

await userService.createSIWEUser(EPHEMERAL_TEST_WALLET);

const result = await controller.createUserJobFolder(
req as Request,
res as Response,
{
name: "Demo Folder",
isPublic: true,
jobs: [],
},
);

expect(result).toEqual({
success: true,
message: expect.stringMatching("success"),
});

const details = await controller.getUserJobFolderById(
req as Request,
res as Response,
data(result).id,
);

expect(details).toStrictEqual(expect.any(JobpostFolder));

jobFolderId = data(result).id;
},
REALLY_LONG_TIME,
);

it(
"should update a job folder",
async () => {
const req: Partial<Request> = {};
const res: Partial<Response> = {};

jest.spyOn(authService, "getSession").mockImplementation(async () => ({
address: EPHEMERAL_TEST_WALLET,
destroy: async (): Promise<void> => {
logger.log("session destroyed");
},
save: async (): Promise<void> => {
logger.log("session saved");
},
}));

const result = await controller.updateUserJobFolder(
req as Request,
res as Response,
jobFolderId,
{
name: "Demo Folder",
isPublic: true,
jobs: [NOT_SO_RANDOM_TEST_SHORT_UUID],
},
);

expect(result).toEqual({
success: true,
message: expect.stringMatching("success"),
});

const details = await controller.getUserJobFolderById(
req as Request,
res as Response,
data(result).id,
);

expect(data(details)).toStrictEqual(expect.any(JobpostFolder));
},
REALLY_LONG_TIME,
);

it(
"should get a users job folders",
async () => {
const req: Partial<Request> = {};
const res: Partial<Response> = {};

jest.spyOn(authService, "getSession").mockImplementation(async () => ({
address: EPHEMERAL_TEST_WALLET,
destroy: async (): Promise<void> => {
logger.log("session destroyed");
},
save: async (): Promise<void> => {
logger.log("session saved");
},
}));

const result = await controller.getUserJobFolders(
req as Request,
res as Response,
);

expect(result).toStrictEqual({
success: true,
message: expect.stringMatching("success"),
data: expect.any(Array<JobpostFolder>),
});
},
REALLY_LONG_TIME,
);

it(
"should delete a job folder",
async () => {
const req: Partial<Request> = {};
const res: Partial<Response> = {};

jest.spyOn(authService, "getSession").mockImplementation(async () => ({
address: EPHEMERAL_TEST_WALLET,
destroy: async (): Promise<void> => {
logger.log("session destroyed");
},
save: async (): Promise<void> => {
logger.log("session saved");
},
}));

const result = await controller.deleteUserJobFolder(
req as Request,
res as Response,
jobFolderId,
);

expect(result).toEqual({
success: true,
message: expect.stringMatching("success"),
});

const details = await controller.getUserJobFolderById(
req as Request,
res as Response,
jobFolderId,
);

expect(data(details)).toBeUndefined();
},
REALLY_LONG_TIME,
);

it(
"should get jobs list with no jobpost and array property duplication",
async () => {
Expand Down
Loading

0 comments on commit 45dde52

Please sign in to comment.