Skip to content

Commit

Permalink
tests: Added tests for deleteVenue.ts
Browse files Browse the repository at this point in the history
- Achieved 100% test coverage for `deleteVenue.ts` file.

Signed-off-by: Akhilender <akhilenderb9@gmail.com>
  • Loading branch information
akhilender-bongirwar committed Mar 31, 2024
1 parent e5f7a9d commit 73f0a5d
Showing 1 changed file with 35 additions and 1 deletion.
36 changes: 35 additions & 1 deletion tests/resolvers/Mutation/deleteVenue.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import "dotenv/config";
import type mongoose from "mongoose";
import { Types } from "mongoose";
import { Organization, Venue, type InterfaceVenue } from "../../../src/models";
import {
Organization,
Venue,
type InterfaceVenue,
AppUserProfile,
} from "../../../src/models";
import type { MutationDeleteVenueArgs } from "../../../src/types/generatedGraphQLTypes";
import { connect, disconnect } from "../../helpers/db";

Expand All @@ -10,6 +15,7 @@ import { afterAll, beforeAll, describe, expect, it, vi } from "vitest";
import {
ORGANIZATION_NOT_AUTHORIZED_ERROR,
ORGANIZATION_NOT_FOUND_ERROR,
USER_NOT_AUTHORIZED_ERROR,
USER_NOT_FOUND_ERROR,
VENUE_NOT_FOUND_ERROR,
} from "../../../src/constants";
Expand Down Expand Up @@ -199,4 +205,32 @@ describe("resolvers -> Mutation -> deleteVenue", () => {
const expectedVenue = await Venue.findById(testVenue?._id);
expect(expectedVenue).toEqual(null);
});

it("throws user not authorized error if current user app profile is not found", async () => {
try {
const args: MutationDeleteVenueArgs = {
id: testVenue2?._id.toString(),
};

await AppUserProfile.deleteOne({
userId: testUser?._id,
});

const context = {
userId: testUser?._id,
};

const { deleteVenue } = await import(
"../../../src/resolvers/Mutation/deleteVenue"
);

await deleteVenue?.({}, args, context);
} catch (error: unknown) {
if (error instanceof NotFoundError) {
expect(error.message).toEqual(USER_NOT_AUTHORIZED_ERROR.MESSAGE);
} else {
fail(`Expected NotFoundError, but got ${error}`);
}
}
});
});

0 comments on commit 73f0a5d

Please sign in to comment.