-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Showing
4 changed files
with
57 additions
and
29 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,32 @@ | ||
import request from "supertest"; | ||
import app from "../../../src/app"; | ||
|
||
import { ObjectId } from "mongodb"; | ||
import * as Misc from "../../../src/utils/misc"; | ||
|
||
const uid = new ObjectId().toHexString(); | ||
const mockApp = request(app); | ||
|
||
describe("DevController", () => { | ||
describe("generate testData", () => { | ||
const isDevEnvironmentMock = vi.spyOn(Misc, "isDevEnvironment"); | ||
|
||
beforeEach(() => { | ||
isDevEnvironmentMock.mockReset(); | ||
isDevEnvironmentMock.mockReturnValue(true); | ||
}); | ||
it("should fail on prod", async () => { | ||
//GIVEN | ||
isDevEnvironmentMock.mockReturnValue(false); | ||
//WHEN | ||
const { body } = await mockApp | ||
.post("/dev/generateData") | ||
.send({ username: "test" }) | ||
.expect(503); | ||
//THEN | ||
expect(body.message).toEqual( | ||
"Development endpoints are only available in DEV mode." | ||
); | ||
}); | ||
}); | ||
}); |
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,22 +1,15 @@ | ||
import { devContract } from "@monkeytype/contracts/dev"; | ||
import { initServer } from "@ts-rest/express"; | ||
import { validate } from "../../middlewares/configuration"; | ||
import { isDevEnvironment } from "../../utils/misc"; | ||
|
||
import * as DevController from "../controllers/dev"; | ||
import { callController } from "../ts-rest-adapter"; | ||
|
||
const onlyAvailableOnDev = validate({ | ||
criteria: () => { | ||
return isDevEnvironment(); | ||
}, | ||
invalidMessage: "Development endpoints are only available in DEV mode.", | ||
}); | ||
import { onlyAvailableOnDev } from "../../middlewares/utility"; | ||
|
||
const s = initServer(); | ||
|
||
export default s.router(devContract, { | ||
generateData: { | ||
middleware: [onlyAvailableOnDev], | ||
middleware: [onlyAvailableOnDev()], | ||
handler: async (r) => callController(DevController.createTestData)(r), | ||
}, | ||
}); |
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