-
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.
- Loading branch information
1 parent
757b2b0
commit 0144832
Showing
5 changed files
with
109 additions
and
7 deletions.
There are no files selected for viewing
60 changes: 60 additions & 0 deletions
60
backend/src/recreation-resource/recreation-resource.controller.spec.ts
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 |
---|---|---|
@@ -1,20 +1,80 @@ | ||
import { Test, TestingModule } from "@nestjs/testing"; | ||
import { INestApplication } from "@nestjs/common"; | ||
import { RecreationResourceController } from "./recreation-resource.controller"; | ||
import { RecreationResourceService } from "./recreation-resource.service"; | ||
import { PrismaService } from "nestjs-prisma"; | ||
import { HttpException } from "@nestjs/common"; | ||
|
||
describe("RecreationResourceController", () => { | ||
let recService: RecreationResourceService; | ||
let controller: RecreationResourceController; | ||
let app: INestApplication; | ||
|
||
beforeEach(async () => { | ||
const module: TestingModule = await Test.createTestingModule({ | ||
controllers: [RecreationResourceController], | ||
providers: [ | ||
RecreationResourceService, | ||
{ | ||
provide: PrismaService, | ||
useValue: {}, | ||
}, | ||
], | ||
}).compile(); | ||
|
||
recService = module.get<RecreationResourceService>( | ||
RecreationResourceService, | ||
); | ||
controller = module.get<RecreationResourceController>( | ||
RecreationResourceController, | ||
); | ||
app = module.createNestApplication(); | ||
await app.init(); | ||
}); | ||
|
||
// Close the app after each test | ||
afterEach(async () => { | ||
await app.close(); | ||
}); | ||
|
||
it("should be defined", () => { | ||
expect(controller).toBeDefined(); | ||
}); | ||
|
||
describe("findAll", () => { | ||
it("should return an array of users", async () => { | ||
const result = []; | ||
result.push({ | ||
forest_file_id: "REC0001", | ||
name: "Rec site 1", | ||
description: "Rec site 1 description", | ||
site_location: "Rec site 1 location", | ||
}); | ||
vi.spyOn(recService, "findAll").mockResolvedValue(result); | ||
expect(await controller.findAll()).toBe(result); | ||
}); | ||
}); | ||
|
||
describe("findOne", () => { | ||
it("should return a Recreation Resource object", async () => { | ||
const result = { | ||
forest_file_id: "REC0001", | ||
name: "Rec site 1", | ||
description: "Rec site 1 description", | ||
site_location: "Rec site 1 location", | ||
}; | ||
vi.spyOn(recService, "findOne").mockResolvedValue(result); | ||
expect(await controller.findOne("REC0001")).toBe(result); | ||
}); | ||
|
||
it("should throw error if recreation resource not found", async () => { | ||
vi.spyOn(recService, "findOne").mockResolvedValue(undefined); | ||
try { | ||
await controller.findOne("REC0001"); | ||
} catch (e) { | ||
expect(e).toBeInstanceOf(HttpException); | ||
expect(e.message).toBe("Recreation Resource not found."); | ||
} | ||
}); | ||
}); | ||
}); |
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
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
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
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