Skip to content
This repository has been archived by the owner on Jul 4, 2023. It is now read-only.

fix(server): fix bizarre duplicate logs #81

Merged
merged 1 commit into from
Apr 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 1 addition & 16 deletions src/commands/serve/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,24 +84,9 @@ export const configureServer = (
serverLogger.warn(
`An endpoint for ${req.path} exists but the query params did not match the configuration`,
)
next()
return next()
}

// TODO ======= finish up by adding tests. maybe extract it out
// const actualQuery = parse(req.url, true).query
// const expectedQuery = parse(request.endpoint, true).query

// const queryMismatches = Object.keys(expectedQuery)
// .map((key) => isQueryMismatch(key, expectedQuery[key], actualQuery[key]))
// .filter((x): x is string => !!x)

// if (queryMismatches.length) {
// res.locals.message = queryMismatches.join('\n')
// res.locals.status = 400
// return next()
// }
// ============================================

if (typeValidator && request.type) {
const problems = await typeValidator.getProblems(req.body, request.type, ProblemType.Request)
serverLogger.warn(
Expand Down
24 changes: 22 additions & 2 deletions src/commands/serve/server/server.integration.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ describe('server', () => {
})

describe('request query strings', () => {
it('gives a 200 when a query matches in a different order', async () => {
it('still responds when a query matches in a different order', async () => {
const configs = [
new ConfigBuilder().withEndpoint('/api/resource?greetings=hello&greetings=bye').build(),
]
Expand All @@ -132,7 +132,27 @@ describe('server', () => {
await request(app).get('/api/resource?greetings=bye&greetings=hello').expect(200)
})

it('gives a 404 if a query does not match', async () => {
it('responds when a query matches a different config', async () => {
const configs = [
new ConfigBuilder()
.withName('Config1')
.withEndpoint('/api/resource?greetings=hello&greetings=bye')
.withResponseBody('nope')
.build(),
new ConfigBuilder()
.withName('Config2')
.withEndpoint('/api/resource?greetings=hi&greetings=bye')
.withResponseCode(202)
.withResponseBody('YES')
.build(),
]

const app = configureServer('example.com', configs)

await request(app).get('/api/resource?greetings=hi&greetings=bye').expect(202).expect('YES')
})

it('gives a 404 if a query does not match any config', async () => {
const configs = [
new ConfigBuilder().withEndpoint('/api/resource?greetings=hello&greetings=bye').build(),
]
Expand Down