-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #283 from AppQuality/refactor-candidates
rework: Refactor candidates
- Loading branch information
Showing
20 changed files
with
837 additions
and
746 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,8 +1,5 @@ | ||
import app from "@src/app"; | ||
import config from "@src/config"; | ||
import connectionManager from "@src/features/db/mysql"; | ||
const PORT = config.port || 3000; | ||
|
||
connectionManager.connectToServer(() => { | ||
app.listen(PORT, () => console.info("api listening on port " + PORT)); | ||
}); | ||
app.listen(PORT, () => console.info("api listening on port " + PORT)); |
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,145 @@ | ||
import getExample from "."; | ||
|
||
describe("Get Example middleware", () => { | ||
it("should return a middleware", () => { | ||
expect(getExample).toBeInstanceOf(Function); | ||
}); | ||
it("Should return false if path does not exists", () => { | ||
const result = getExample( | ||
{ definition: { paths: {} } }, | ||
"/endpoint", | ||
"get", | ||
"400", | ||
undefined | ||
); | ||
expect(result).toBe(false); | ||
}); | ||
it("Should return false if path does not have method", () => { | ||
const result = getExample( | ||
{ definition: { paths: { "/endpoint": {} } } }, | ||
"/endpoint", | ||
"get", | ||
"400", | ||
undefined | ||
); | ||
expect(result).toBe(false); | ||
}); | ||
it("Should return false if path method does not have response", () => { | ||
const result = getExample( | ||
{ definition: { paths: { "/endpoint": { get: { responses: {} } } } } }, | ||
"/endpoint", | ||
"get", | ||
"400", | ||
undefined | ||
); | ||
expect(result).toBe(false); | ||
}); | ||
it("Should return false if path method does not have response with requested status", () => { | ||
const result = getExample( | ||
{ | ||
definition: { | ||
paths: { "/endpoint": { get: { responses: { "200": {} } } } }, | ||
}, | ||
}, | ||
"/endpoint", | ||
"get", | ||
"400", | ||
undefined | ||
); | ||
expect(result).toBe(false); | ||
}); | ||
it("Should return false if path method response does not have content", () => { | ||
const result = getExample( | ||
{ | ||
definition: { | ||
paths: { "/endpoint": { get: { responses: { "400": {} } } } }, | ||
}, | ||
}, | ||
"/endpoint", | ||
"get", | ||
"400", | ||
undefined | ||
); | ||
expect(result).toBe(false); | ||
}); | ||
it("Should return false if path method response does not have application/json content", () => { | ||
const result = getExample( | ||
{ | ||
definition: { | ||
paths: { | ||
"/endpoint": { | ||
get: { responses: { "400": { content: { "text/html": {} } } } }, | ||
}, | ||
}, | ||
}, | ||
}, | ||
"/endpoint", | ||
"get", | ||
"400", | ||
undefined | ||
); | ||
expect(result).toBe(false); | ||
}); | ||
it("Should return requested example if a specific example is requested", () => { | ||
const result = getExample( | ||
{ | ||
definition: { | ||
paths: { | ||
"/endpoint": { | ||
get: { | ||
responses: { | ||
"400": { | ||
content: { | ||
"application/json": { | ||
examples: { | ||
"my-example": { value: { hello: "world" } }, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
"/endpoint", | ||
"get", | ||
"400", | ||
"my-example" | ||
); | ||
expect(result).toEqual({ hello: "world" }); | ||
}); | ||
|
||
it("Should return first example if no specific example is requested", () => { | ||
const result = getExample( | ||
{ | ||
definition: { | ||
paths: { | ||
"/endpoint": { | ||
get: { | ||
responses: { | ||
"400": { | ||
content: { | ||
"application/json": { | ||
examples: { | ||
"my-other-example": { value: { hello: "universe" } }, | ||
"my-example": { value: { hello: "world" } }, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
"/endpoint", | ||
"get", | ||
"400", | ||
undefined | ||
); | ||
expect(result).toEqual({ hello: "universe" }); | ||
}); | ||
}); |
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,13 @@ | ||
import app from "@src/app"; | ||
import request from "supertest"; | ||
|
||
describe("Check NotFound middleware", () => { | ||
it("should return 404 and a not found err", async () => { | ||
const response = await request(app).get("/fakes/route-that-doesnt-exist"); | ||
|
||
expect(response.status).toBe(404); | ||
expect(response.body).toEqual({ | ||
err: "not found", | ||
}); | ||
}); | ||
}); |
File renamed without changes.
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,23 @@ | ||
import notImplemented from "."; | ||
describe("Not Implemented", () => { | ||
it("should return a not implemented error", async () => { | ||
const json = jest.fn(); | ||
const status = jest.fn(() => ({ json })); | ||
// @ts-ignore | ||
const middleware = notImplemented({ | ||
// @ts-ignore | ||
mockResponseForOperation: (operation) => ({ | ||
status: 501, | ||
mock: { | ||
message: "Not Implemented", | ||
}, | ||
}), | ||
}); | ||
// @ts-ignore | ||
middleware({ operation: { operationId: "" } }, {}, { status }); | ||
expect(json).toBeCalledTimes(1); | ||
expect(json).toBeCalledWith({ message: "Not Implemented" }); | ||
expect(status).toBeCalledTimes(1); | ||
expect(status).toBeCalledWith(501); | ||
}); | ||
}); |
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.