forked from ubiquity/pay.ubq.fi
-
Notifications
You must be signed in to change notification settings - Fork 0
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
2 changed files
with
102 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { env, waitOnExecutionContext } from "cloudflare:test"; | ||
import { describe, it, expect } from "vitest"; | ||
import { onRequest, getRedeemCode } from "./get-redeem-code"; | ||
import { createContext, DEFAULT_BASE_URL } from "../vitest/helpers"; | ||
import { getAccessToken } from "./helpers"; | ||
|
||
describe("Get Order", () => { | ||
it("throws 404 for non-existent order", async () => { | ||
const transactionId = String(1); | ||
const signedMessage = ""; | ||
const wallet = ""; | ||
const permitSig = ""; | ||
|
||
const { ctx, eventCtx } = createContext(DEFAULT_BASE_URL, { transactionId, signedMessage, wallet, permitSig }); | ||
|
||
const response = await onRequest(eventCtx); | ||
await waitOnExecutionContext(ctx); | ||
|
||
expect(response.status).toBe(404); | ||
expect(await response.text()).toContain("Order not found"); | ||
}); | ||
}); | ||
|
||
describe("Redeem code helper", () => { | ||
it("get redeem code for account and existing transaction", async () => { | ||
const transactionId = 1; | ||
const accessToken = await getAccessToken(env); | ||
void expect(() => getRedeemCode(transactionId, accessToken)).rejects.toThrowError( | ||
'Error from Reloadly API: {"status":401,"message":"Full authentication is required to access this resource"}' | ||
); | ||
}); | ||
|
||
it("get redeem code for other account", async () => { | ||
const transactionId = 1; | ||
const accessToken = await getAccessToken(env); | ||
void expect(() => getRedeemCode(transactionId, accessToken)).rejects.toThrowError( | ||
'Error from Reloadly API: {"status":401,"message":"Full authentication is required to access this resource"}' | ||
); | ||
}); | ||
|
||
it("get redeem code for account and inexistent transaction", async () => { | ||
const transactionId = 1; | ||
const accessToken = await getAccessToken(env); | ||
void expect(() => getRedeemCode(transactionId, accessToken)).rejects.toThrowError( | ||
'Error from Reloadly API: {"status":401,"mess":"Full authentication is required to access this resource"}' | ||
); | ||
}); | ||
}); |
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,54 @@ | ||
import { waitOnExecutionContext, env } from "cloudflare:test"; | ||
import { describe, it, expect, beforeAll } from "vitest"; | ||
import { onRequest /*getGiftCardById, orderGiftCard, isDuplicateOrder, getExchangeRate, validateTransaction*/ } from "./post-order"; | ||
import { createContext, DEFAULT_BASE_URL } from "../vitest/helpers"; | ||
import { getGiftCards } from "./list-gift-cards"; | ||
import { getAccessToken } from "./helpers"; | ||
|
||
let giftCards = []; | ||
|
||
describe("Post Order", () => { | ||
beforeAll(async () => { | ||
const accessToken = await getAccessToken(env); | ||
const country = "US"; | ||
const productQuery = "visa"; | ||
|
||
// Fetch available cards | ||
const cards = await getGiftCards(productQuery, country, accessToken); | ||
expect(cards.length, `No cards for ${country} country`).toBeGreaterThan(0); | ||
giftCards = cards; | ||
|
||
// Create mock permits | ||
const response = await fetch("http://localhost:3000/create-mock-app"); | ||
const resp = (await response.json()) as { success: boolean }; | ||
expect(resp.success).toBe(true); | ||
}); | ||
|
||
it("simple order", async () => { | ||
const { productId } = giftCards[0]; | ||
const chainId = "1"; | ||
let response; | ||
|
||
response = await fetch("/create-mock-permit"); | ||
// const permit = await response.json(); | ||
|
||
response = await fetch("/create-mock-transfer"); | ||
const resp = (await response.json()) as { txHash: string }; | ||
|
||
const { ctx, eventCtx } = createContext(DEFAULT_BASE_URL, { productId, txHash: resp.txHash, chainId }); | ||
|
||
response = await onRequest(eventCtx); | ||
await waitOnExecutionContext(ctx); | ||
|
||
expect(response.status).toBe(404); | ||
expect(await response.text()).toContain("Order not found"); | ||
}); | ||
}); | ||
|
||
describe("Post order helpers", () => { | ||
it("wrong credentials", async () => { | ||
// void expect(() => getTransactionFromOrderId("asd", { token: "token", isSandbox: true })).rejects.toThrowError( | ||
// 'Error from Reloadly API: {"status":401,"message":"Full authentication is required to access this resource"}' | ||
// ); | ||
}); | ||
}); |