Skip to content

Commit 6841b72

Browse files
committed
fix failing tests
1 parent 4cfccd0 commit 6841b72

File tree

6 files changed

+20
-5
lines changed

6 files changed

+20
-5
lines changed

src/utilities/loadSampleData.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ async function formatDatabase(): Promise<void> {
7474
Post.deleteMany({}),
7575
AppUserProfile.deleteMany({}),
7676
RecurrenceRule.deleteMany({}),
77+
Venue.deleteMany({}),
7778
]);
7879
console.log("Cleared all collections\n");
7980
}

tests/resolvers/Query/getVolunteerRanks.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ describe("resolvers -> Query -> getVolunteerRanks", () => {
7777
{},
7878
)) as unknown as VolunteerRank[];
7979

80-
expect(volunteerRanks[0].hoursVolunteered).toEqual(6);
80+
expect(volunteerRanks[0].hoursVolunteered).toEqual(2);
8181
expect(volunteerRanks[0].user._id).toEqual(testUser1?._id);
8282
expect(volunteerRanks[0].rank).toEqual(1);
8383
});
@@ -94,7 +94,7 @@ describe("resolvers -> Query -> getVolunteerRanks", () => {
9494
},
9595
{},
9696
)) as unknown as VolunteerRank[];
97-
expect(volunteerRanks[0].hoursVolunteered).toEqual(8);
97+
expect(volunteerRanks[0].hoursVolunteered).toEqual(2);
9898
expect(volunteerRanks[0].user._id).toEqual(testUser1?._id);
9999
expect(volunteerRanks[0].rank).toEqual(1);
100100
});

tests/setup/checkExistingMongoDB.spec.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ describe("Setup -> checkExistingMongoDB", () => {
99
});
1010
it("should return the first valid URL when a connection is found", async () => {
1111
const result = await checkExistingMongoDB();
12+
console.log(result);
13+
console.log(process.env.MONGO_DB_URL);
1214
expect(result).toBe(process.env.MONGO_DB_URL);
1315
});
1416

@@ -60,7 +62,8 @@ describe("Setup -> checkExistingMongoDB", () => {
6062
expect(result).toBe(false);
6163
});
6264
it("should return the first valid URL when a connection is found", async () => {
63-
process.env.MONGO_DB_URL = "mongodb://localhost:27017/talawa-api";
65+
process.env.MONGO_DB_URL =
66+
"mongodb://localhost:27017/test?replicaSet=rs0&directConnection=true";
6467
const result = await checkExistingMongoDB();
6568
expect(result).toBe(process.env.MONGO_DB_URL);
6669
});

tests/setup/mongoDB.spec.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,8 @@ describe("Setup -> mongoDB", () => {
117117
});
118118

119119
it("should return true for a successfull connection with MongoDB", async () => {
120-
const url = "mongodb://localhost:27017";
120+
const url =
121+
"mongodb://localhost:27017/test?replicaSet=rs0&directConnection=true";
121122
const result = await module.checkConnection(url);
122123
expect(result).toEqual(true);
123124
});

tests/utilities/loadSampleData.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import { execSync } from "child_process";
1515

1616
describe("Sample Data Import Tests", () => {
1717
beforeAll(async () => {
18-
await connect();
18+
await connect("talawa-api");
1919
});
2020

2121
afterAll(async () => {

vite.config.mts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
import { defineConfig } from "vitest/config";
2+
import path from 'node:path';
23

34
export default defineConfig({
5+
resolve: {
6+
alias: {
7+
'@constants': path.resolve(__dirname, 'src/constants'),
8+
'@setup': path.resolve(__dirname, 'src/setup'),
9+
'@utilities': path.resolve(__dirname, 'src/utilities'),
10+
},
11+
},
12+
413
test: {
514
setupFiles: ["./config/vitestSetup.ts"],
615

@@ -36,6 +45,7 @@ export default defineConfig({
3645
"src/utilities/sample_data/*",
3746
"src/utilities/loadSampleData.ts",
3847
],
48+
3949

4050
// This is used to tell vitest which coverage provider to use. c8 is the newer and
4151
// recommended coverage provider for node.js applications. You can swap it with

0 commit comments

Comments
 (0)