Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: responses without default key (#1751)
* fix: responses without default key * fix: prettier errors * test: add more tests and rename folder * chore: fix prettier formatting
- Loading branch information
1 parent
c85a192
commit 9ce688a
Showing
7 changed files
with
98 additions
and
4 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
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,34 @@ | ||
import assert from "node:assert" | ||
import { join } from "desm" | ||
import { BASE_URL } from "../../config.js" | ||
import { setup, teardown } from "../../_testHelpers/index.js" | ||
|
||
describe("default response", function desc() { | ||
beforeEach(() => | ||
setup({ | ||
servicePath: join(import.meta.url, "src"), | ||
}), | ||
) | ||
|
||
afterEach(() => teardown()) | ||
|
||
it("when no default response is provided", async () => { | ||
const url = new URL("/dev/product_without_default", BASE_URL) | ||
const response = await fetch(url) | ||
const json = await response.json() | ||
|
||
assert.deepEqual(json, { | ||
foo: "bar", | ||
}) | ||
}) | ||
|
||
it("when default response is provided", async () => { | ||
const url = new URL("/dev/product_with_default", BASE_URL) | ||
const response = await fetch(url) | ||
const json = await response.json() | ||
|
||
assert.deepEqual(json, { | ||
foo: "bar", | ||
}) | ||
}) | ||
}) |
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,10 @@ | ||
const { stringify } = JSON | ||
|
||
export const hello = async () => { | ||
return { | ||
body: stringify({ | ||
foo: "bar", | ||
}), | ||
statusCode: 200, | ||
} | ||
} |
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,3 @@ | ||
{ | ||
"type": "module" | ||
} |
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,43 @@ | ||
service: uncategorized-tests | ||
|
||
frameworkVersion: "3" | ||
|
||
plugins: | ||
- ../../../../src/index.js | ||
|
||
provider: | ||
name: aws | ||
region: us-east-1 | ||
runtime: nodejs18.x | ||
stage: dev | ||
apiGateway: | ||
minimumCompressionSize: 1024 | ||
shouldStartNameWithService: true | ||
|
||
functions: | ||
helloWithoutDefault: | ||
events: | ||
- http: | ||
method: get | ||
path: /product_without_default | ||
responses: | ||
200: | ||
description: This is a success response | ||
bodyType: Product | ||
handler: handler.hello | ||
helloWithDefault: | ||
events: | ||
- http: | ||
method: get | ||
path: /product_with_default | ||
responses: | ||
default: | ||
description: This is a default response | ||
bodyType: Product | ||
200: | ||
description: This is a success response | ||
bodyType: Product | ||
handler: handler.hello | ||
|
||
package: | ||
individually: true |