-
-
Notifications
You must be signed in to change notification settings - Fork 284
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(platform-fastify): map request/reply methods to PlatformRequest…
- Loading branch information
Showing
10 changed files
with
173 additions
and
311 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,18 @@ | ||
// For a detailed explanation regarding each configuration property, visit: | ||
// https://jestjs.io/docs/en/configuration.html | ||
|
||
module.exports = { | ||
...require("@tsed/jest-config"), | ||
roots: ["<rootDir>/src", "<rootDir>/test"], | ||
moduleNameMapper: { | ||
"^@tsed/platform-fastify$": "<rootDir>/src/index.ts" | ||
}, | ||
coverageThreshold: { | ||
global: { | ||
statements: 98.28, | ||
branches: 92.59, | ||
functions: 100, | ||
lines: 98.28 | ||
} | ||
} | ||
}; |
61 changes: 6 additions & 55 deletions
61
packages/platform/platform-fastify/src/components/PlatformFastify.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,82 +1,33 @@ | ||
import {PlatformBuilder} from "@tsed/common"; | ||
import Sinon from "sinon"; | ||
import {expect} from "chai"; | ||
import {PlatformFastify} from "./PlatformFastify"; | ||
|
||
const sandbox = Sinon.createSandbox(); | ||
|
||
class Server {} | ||
|
||
describe("PlatformFastify", () => { | ||
describe("create()", () => { | ||
beforeEach(() => { | ||
sandbox.stub(PlatformBuilder, "create"); | ||
jest.spyOn(PlatformBuilder, "create").mockReturnValue({}); | ||
}); | ||
afterEach(() => sandbox.restore()); | ||
afterEach(() => jest.resetAllMocks()); | ||
it("should create platform", () => { | ||
PlatformFastify.create(Server, {}); | ||
|
||
expect(PlatformBuilder.create).to.have.been.calledWithExactly(Server, { | ||
expect(PlatformBuilder.create).toHaveBeenCalledWith(Server, { | ||
adapter: PlatformFastify | ||
}); | ||
}); | ||
}); | ||
describe("bootstrap()", () => { | ||
beforeEach(() => { | ||
sandbox.stub(PlatformBuilder, "bootstrap"); | ||
jest.spyOn(PlatformBuilder, "bootstrap").mockReturnValue({}); | ||
}); | ||
afterEach(() => sandbox.restore()); | ||
afterEach(() => jest.resetAllMocks()); | ||
it("should create platform", async () => { | ||
await PlatformFastify.bootstrap(Server, {}); | ||
|
||
expect(PlatformBuilder.bootstrap).to.have.been.calledWithExactly(Server, { | ||
expect(PlatformBuilder.bootstrap).toHaveBeenCalledWith(Server, { | ||
adapter: PlatformFastify | ||
}); | ||
}); | ||
}); | ||
describe("bodyParser()", () => { | ||
afterEach(() => sandbox.restore()); | ||
it("should return the body parser (json) ", () => { | ||
const stub = sandbox.stub().returns("body"); | ||
|
||
const platform = PlatformFastify.create(Server, { | ||
fastify: { | ||
bodyParser: stub | ||
} | ||
}); | ||
|
||
const result = platform.adapter.bodyParser("json", {strict: true}); | ||
|
||
expect(result).to.equal("body"); | ||
expect(stub).to.have.been.calledWithExactly({strict: true}); | ||
}); | ||
it("should return the body parser (raw) ", () => { | ||
const stub = sandbox.stub().returns("body"); | ||
|
||
const platform = PlatformFastify.create(Server, { | ||
fastify: { | ||
bodyParser: stub | ||
} | ||
}); | ||
|
||
const result = platform.adapter.bodyParser("raw", {strict: true}); | ||
|
||
expect(result).to.equal("body"); | ||
expect(stub).to.have.been.calledWithExactly({strict: true}); | ||
}); | ||
it("should return the body parser (urlencoded) ", () => { | ||
const stub = sandbox.stub().returns("body"); | ||
|
||
const platform = PlatformFastify.create(Server, { | ||
fastify: { | ||
bodyParser: stub | ||
} | ||
}); | ||
|
||
const result = platform.adapter.bodyParser("urlencoded", {strict: true}); | ||
|
||
expect(result).to.equal("body"); | ||
expect(stub).to.have.been.calledWithExactly({strict: true}); | ||
}); | ||
}); | ||
}); |
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
Oops, something went wrong.