Skip to content

Commit

Permalink
100% code coverage for file
Browse files Browse the repository at this point in the history
  • Loading branch information
git-init-priyanshu committed Apr 4, 2024
1 parent 4ebb50e commit 2475815
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions tests/resolvers/Mutation/deleteAdvertisement.spec.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import "dotenv/config";
import type mongoose from "mongoose";
import type { MutationCreateAdvertisementArgs } from "../../../src/types/generatedGraphQLTypes";
import { Types } from "mongoose";
import { connect, disconnect } from "../../helpers/db";

import {
afterAll,
afterEach,
Expand All @@ -12,6 +11,11 @@ import {
it,
vi,
} from "vitest";

import type {
MutationCreateAdvertisementArgs,
MutationDeleteAdvertisementArgs,
} from "../../../src/types/generatedGraphQLTypes";
import {
ADVERTISEMENT_NOT_FOUND_ERROR,
USER_NOT_AUTHORIZED_ERROR,
Expand Down Expand Up @@ -68,20 +72,22 @@ describe("resolvers -> Mutation -> deleteAdvertisement", () => {
});

it(`throws NotFoundError if no user exists with _id === context.userId `, async () => {
// deleting
const { deleteAdvertisement } = await import(
"../../../src/resolvers/Mutation/deleteAdvertisement"
);
const context = {
userId: "123456789sdfghjk",
};
const { requestContext } = await import("../../../src/libraries");

const spy = vi
.spyOn(requestContext, "translate")
.mockImplementationOnce((message: string) => `Translated ${message}`);

try {
await deleteAdvertisement?.({}, { id: testAdvertisement._id }, context);
const args: MutationDeleteAdvertisementArgs = {
id: "",
};
const context = { userId: new Types.ObjectId().toString() };

const { deleteAdvertisement } = await import(
"../../../src/resolvers/Mutation/deleteAdvertisement"
);
await deleteAdvertisement?.({}, args, context);
} catch (error: unknown) {
if (!(error instanceof ApplicationError)) return;
expect(spy).toBeCalledWith(USER_NOT_FOUND_ERROR.MESSAGE);
Expand Down

0 comments on commit 2475815

Please sign in to comment.