Skip to content

fix: failing test for background functions #2123

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
Closed
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
13 changes: 11 additions & 2 deletions cypress/e2e/default/api.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,17 @@ describe('Dynamic API routes', () => {

describe('Extended API routes', () => {
it('returns HTTP 202 Accepted for background route', () => {
cy.request('/api/hello-background').then((response) => {
expect(response.status).to.equal(202)
cy.request('POST', 'https://webhook.site/token').then((tokenResponse) => {
const token = tokenResponse.body.uuid
cy.request('POST', `/api/hello-background`, { token }).then((response) => {
expect(response.status).to.equal(202)

cy.wait(100)

cy.request(`https://webhook.site/token/${token}/request/latest`).then(response => {
expect(response.status).to.equal(200)
})
})
})
})
it('correctly returns 404 for scheduled route', () => {
Expand Down
4 changes: 3 additions & 1 deletion demos/default/pages/api/hello-background.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
export default (req, res) => {
export default async (req, res) => {
await fetch(`https://webhook.site/${req.body.token}`)

Check failure

Code scanning / CodeQL

Server-side request forgery

The [URL](1) of this request depends on a [user-provided value](2).

res.setHeader('Content-Type', 'application/json')
res.status(200)
res.json({ message: 'hello world :)' })
Expand Down