-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adds test for activities controller functions
- Loading branch information
1 parent
6b42b5c
commit c2fd3d0
Showing
3 changed files
with
42 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { dbConnect, dbDisconnect } from "../dbHandler"; | ||
import { ActivitiesType } from "../../models/activities.model"; | ||
import { activityDummyData1 } from "./dummyData"; | ||
import { createActivity, getAllActivities } from "../../controllers/activities.controller"; | ||
Check failure on line 4 in src/tests/controllers.tests/activities.test.ts GitHub Actions / build (18.x)
|
||
import { describe, test, expect, beforeEach, afterEach } from "vitest"; | ||
|
||
describe("Activities controller tests", () => { | ||
beforeEach(async () => dbConnect()); | ||
afterEach(async () => dbDisconnect()); | ||
|
||
test("Adds and retrieves an activity", async () => { | ||
await createActivity(activityDummyData1 as ActivitiesType); | ||
const returnedActivities = await getAllActivities(activityDummyData1.user); | ||
expect(returnedActivities.length).to.equal(1); | ||
expect(returnedActivities[0]).toMatchObject(activityDummyData1); | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
export const activityDummyData1 = { | ||
user: "test", | ||
itemName: "activitesItem1", | ||
bullets: ["example bullet"], | ||
title: "title", | ||
subtitle: "subtitle", | ||
year: "year", | ||
location: "location", | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import mongoose from "mongoose"; | ||
import { MongoMemoryServer } from 'mongodb-memory-server'; | ||
|
||
let mongoServer: MongoMemoryServer; | ||
|
||
export const dbConnect = async () => { | ||
mongoServer = await MongoMemoryServer.create(); | ||
const uri = mongoServer.getUri(); | ||
await mongoose.connect(uri); | ||
}; | ||
|
||
export const dbDisconnect = async () => { | ||
await mongoose.connection.dropDatabase(); | ||
await mongoose.connection.close(); | ||
await mongoServer.stop(); | ||
}; |