-
-
Notifications
You must be signed in to change notification settings - Fork 286
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(testcontainers-mongo): update readme package and add documentation
- Loading branch information
Showing
7 changed files
with
282 additions
and
169 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import {PlatformTest} from "@tsed/common"; | ||
import {TestContainersMongo} from "@tsed/testcontainers-mongo"; | ||
import * as SuperTest from "supertest"; | ||
import {Server} from "../Server"; | ||
|
||
describe("Rest", () => { | ||
beforeAll(TestContainersMongo.bootstrap(Server)); // Create a server with mocked database | ||
afterAll(() => TestContainersMongo.reset()); // reset database and injector | ||
|
||
describe("GET /rest/calendars", () => { | ||
it("should do something", async () => { | ||
const request = SuperTest(PlatformTest.callback()); | ||
const response = await request.get("/rest/calendars").expect(200); | ||
|
||
expect(typeof response.body).toEqual("array"); | ||
}); | ||
}); | ||
}); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import {PlatformTest} from "@tsed/common"; | ||
import {Property, Required} from "@tsed/schema"; | ||
import {Model, MongooseModel, ObjectID, PostHook, PreHook, Unique} from "@tsed/mongoose"; | ||
import {TestContainersMongo} from "@tsed/testcontainers-mongo"; | ||
|
||
@Model({schemaOptions: {timestamps: true}}) | ||
@PreHook("save", (user: UserModel, next: any) => { | ||
user.pre = "hello pre"; | ||
|
||
next(); | ||
}) | ||
@PostHook("save", (user: UserModel, next: any) => { | ||
user.post = "hello post"; | ||
|
||
next(); | ||
}) | ||
export class UserModel { | ||
@ObjectID("id") | ||
_id: string; | ||
|
||
@Property() | ||
@Required() | ||
@Unique() | ||
email: string; | ||
|
||
@Property() | ||
pre: string; | ||
|
||
@Property() | ||
post: string; | ||
} | ||
|
||
describe("UserModel", () => { | ||
beforeEach(() => TestContainersMongo.create()); | ||
afterEach(() => TestContainersMongo.reset("users")); // clean users collection after each test | ||
|
||
it("should run pre and post hook", async () => { | ||
const userModel = PlatformTest.get<MongooseModel<UserModel>>(UserModel); | ||
|
||
// GIVEN | ||
const user = new userModel({ | ||
email: "[email protected]" | ||
}); | ||
|
||
// WHEN | ||
await user.save(); | ||
|
||
// THEN | ||
expect(user.pre).toEqual("hello pre"); | ||
expect(user.post).toEqual("hello post"); | ||
}); | ||
}); |
Oops, something went wrong.