-
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.
- Loading branch information
Showing
1 changed file
with
16 additions
and
10 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 |
---|---|---|
|
@@ -12,20 +12,20 @@ type Invoice = { | |
type Charge = { | ||
invoice: Invoice; | ||
success: boolean; | ||
counter: number | ||
}; | ||
|
||
const header = `test-header-foo` | ||
const headerValue = `header-bar` | ||
const payload: Invoice = { date: 123, email: "[email protected]", amount: 10 } | ||
|
||
let counter = 0; | ||
const attemptCharge = () => { | ||
const attemptCharge = (counter: number) => { | ||
counter += 1; | ||
if (counter === 3) { | ||
counter = 0; | ||
return true; | ||
return { success: true, counter }; | ||
} | ||
return false; | ||
return { success: false, counter }; | ||
}; | ||
|
||
export const { POST, GET } = testServe( | ||
|
@@ -36,13 +36,19 @@ export const { POST, GET } = testServe( | |
expect(typeof invoice, typeof payload); | ||
expect(JSON.stringify(invoice), JSON.stringify(payload)); | ||
|
||
let charge: Charge = { | ||
success: false, | ||
counter: 0, | ||
invoice | ||
} | ||
|
||
for (let index = 0; index < 3; index++) { | ||
const charge = await context.run("attemptCharge", () => { | ||
const success = attemptCharge(); | ||
const charge: Charge = { invoice, success }; | ||
return charge; | ||
charge = await context.run("attemptCharge", () => { | ||
const { success, counter } = attemptCharge(charge.counter); | ||
const newCharge: Charge = { invoice, success, counter }; | ||
return newCharge; | ||
}); | ||
|
||
if (charge.success) { | ||
const [updateDb, receipt, sleepResult] = await Promise.all([ | ||
context.run("updateDb", () => { | ||
|
@@ -82,4 +88,4 @@ export const { POST, GET } = testServe( | |
[ header ]: headerValue | ||
} | ||
} | ||
) | ||
) |