-
-
Notifications
You must be signed in to change notification settings - Fork 290
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(test): Fix TestContext.create issue
- Loading branch information
Showing
25 changed files
with
491 additions
and
552 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
--require ts-node/register | ||
--require tsconfig-paths/register | ||
--require scripts/mocha/register | ||
--bail | ||
{src,test}/**/*.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
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 |
---|---|---|
|
@@ -937,6 +937,14 @@ create-error-class@^3.0.0: | |
dependencies: | ||
capture-stack-trace "^1.0.0" | ||
|
||
[email protected]: | ||
version "5.2.0" | ||
resolved "https://registry.yarnpkg.com/cross-env/-/cross-env-5.2.0.tgz#6ecd4c015d5773e614039ee529076669b9d126f2" | ||
integrity sha512-jtdNFfFW1hB7sMhr/H6rW1Z45LFqyI431m3qU6bFXcQ3Eh7LtBuG3h74o7ohHZ3crrRkkqHlo4jYHFPcjroANg== | ||
dependencies: | ||
cross-spawn "^6.0.5" | ||
is-windows "^1.0.0" | ||
|
||
cross-spawn@^4: | ||
version "4.0.2" | ||
resolved "https://registry.yarnpkg.com/cross-spawn/-/cross-spawn-4.0.2.tgz#7b9247621c23adfdd3856004a823cbe397424d41" | ||
|
@@ -952,7 +960,7 @@ cross-spawn@^5.0.1: | |
shebang-command "^1.2.0" | ||
which "^1.2.9" | ||
|
||
cross-spawn@^6.0.0: | ||
cross-spawn@^6.0.0, cross-spawn@^6.0.5: | ||
version "6.0.5" | ||
resolved "https://registry.yarnpkg.com/cross-spawn/-/cross-spawn-6.0.5.tgz#4a5ec7c64dfae22c3a14124dbacdee846d80cbc4" | ||
integrity sha512-eTVLrBSt7fjbDygz805pMnstIs2VTBNkRm0qxZd+M7A5XDdxVRWO5MxGBXZhjY4cqLYLdtrGqRf8mBPmzwSpWQ== | ||
|
@@ -1823,7 +1831,7 @@ is-stream@^1.0.0, is-stream@^1.0.1, is-stream@^1.1.0: | |
version "1.1.0" | ||
resolved "https://registry.yarnpkg.com/is-stream/-/is-stream-1.1.0.tgz#12d4a3dd4e68e0b79ceb8dbc84173ae80d91ca44" | ||
|
||
is-windows@^1.0.2: | ||
is-windows@^1.0.0, is-windows@^1.0.2: | ||
version "1.0.2" | ||
resolved "https://registry.yarnpkg.com/is-windows/-/is-windows-1.0.2.tgz#d1850eb9791ecd18e6182ce12a30f396634bb19d" | ||
|
||
|
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,12 @@ | ||
const Chai = require("chai"); | ||
const ChaiAsPromised = require("chai-as-promised"); | ||
const SinonChai = require("sinon-chai"); | ||
|
||
Chai.should(); | ||
Chai.use(SinonChai); | ||
Chai.use(ChaiAsPromised); | ||
|
||
process.on("unhandledRejection", (reason, p) => { | ||
console.log("Unhandled Rejection at: Promise", p, "reason:", reason); | ||
// application specific logging, throwing an error, or other logic here | ||
}); |
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
41 changes: 41 additions & 0 deletions
41
integration/passportjs/src/controllers/calendars/CalendarCtrl.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 |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import {TestContext} from "@tsed/testing"; | ||
import {expect} from "chai"; | ||
import * as Sinon from "sinon"; | ||
import {CalendarsService} from "../../services/calendars/CalendarsService"; | ||
import {MemoryStorage} from "../../services/storage/MemoryStorage"; | ||
import {CalendarCtrl} from "./CalendarCtrl"; | ||
|
||
describe("CalendarsCtrl", () => { | ||
describe("without IOC", () => { | ||
it("should do something", () => { | ||
// GIVEN | ||
const calendarsCtrl = new CalendarCtrl(new CalendarsService(new MemoryStorage())); | ||
|
||
expect(calendarsCtrl).to.be.an.instanceof(CalendarCtrl); | ||
}); | ||
}); | ||
|
||
describe("with mocking dependencies", () => { | ||
before(() => TestContext.create()); | ||
after(() => TestContext.reset()); | ||
|
||
it("should return the expected result", () => { | ||
// GIVEN | ||
const calendarsService = { | ||
find: Sinon.stub().returns(Promise.resolve({id: "1"})) | ||
}; | ||
|
||
const calendarController = TestContext.invoke(CalendarCtrl, [ | ||
{provide: CalendarsService, use: calendarsService} | ||
]); | ||
|
||
// WHEN | ||
const result = calendarController.get("1"); | ||
|
||
// THEN | ||
result.should.eventually.deep.equal({id: "1"}); | ||
calendarsService.find.should.be.calledWithExactly("1"); | ||
expect(calendarController.calendarsService).to.equal(calendarsService); | ||
}); | ||
}); | ||
}); |
79 changes: 79 additions & 0 deletions
79
integration/passportjs/src/controllers/calendars/CalendarCtrl.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 |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import { | ||
Authenticated, | ||
BodyParams, | ||
Controller, | ||
Delete, | ||
Get, | ||
PathParams, | ||
Post, | ||
Put, | ||
Required, | ||
Status | ||
} from "@tsed/common"; | ||
import {NotFound} from "ts-httpexceptions"; | ||
import {Calendar} from "../../interfaces/Calendar"; | ||
import {CalendarsService} from "../../services/calendars/CalendarsService"; | ||
import {EventsCtrl} from "../events/EventsCtrl"; | ||
|
||
/** | ||
* Add @Controller annotation to declare your class as Router controller. | ||
* The first param is the global path for your controller. | ||
* The others params is the controller dependencies. | ||
* | ||
* In this case, EventsCtrl is a dependency of CalendarsCtrl. | ||
* All routes of EventsCtrl will be mounted on the `/calendars` path. | ||
*/ | ||
@Controller("/calendars", EventsCtrl) | ||
export class CalendarCtrl { | ||
|
||
constructor(private calendarsService: CalendarsService) { | ||
|
||
} | ||
|
||
@Get("/:id") | ||
async get(@Required() @PathParams("id") id: string): Promise<Calendar> { | ||
|
||
const calendar = await this.calendarsService.find(id); | ||
|
||
if (calendar) { | ||
return calendar; | ||
} | ||
|
||
throw new NotFound("Calendar not found"); | ||
} | ||
|
||
@Put("/") | ||
save(@BodyParams("name") name: string) { | ||
return this.calendarsService.create(name); | ||
} | ||
|
||
/** | ||
* | ||
* @param id | ||
* @param name | ||
* @returns {Promise<Calendar>} | ||
*/ | ||
@Post("/:id") | ||
async update(@PathParams("id") @Required() id: string, | ||
@BodyParams("name") @Required() name: string): Promise<Calendar> { | ||
return this.calendarsService.update({id, name}); | ||
} | ||
|
||
/** | ||
* | ||
* @param id | ||
* @returns {{id: string, name: string}} | ||
*/ | ||
@Delete("/") | ||
@Authenticated() | ||
@Status(204) | ||
async remove(@BodyParams("id") @Required() id: string): Promise<void> { | ||
this.calendarsService.remove(id); | ||
} | ||
|
||
@Get("/") | ||
@Authenticated() | ||
async getAllCalendars(): Promise<Calendar[]> { | ||
return this.calendarsService.query(); | ||
} | ||
} |
53 changes: 0 additions & 53 deletions
53
integration/passportjs/src/controllers/calendars/CalendarsCtrl.spec.ts
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.