mirror of
https://github.com/jjbrunton/Sauci.git
synced 2026-10-31 18:19:43 +00:00
fix(tests): narrow redeemed profile
Assert that the profile lookup returned a row before reading premium status so Deno strict type checking can execute the Supabase integration suite.
This commit is contained in:
1 parent
d43ae1ef05
commit
d869592a8b
1 file changed
+43
-36
@@ -1,48 +1,55 @@
|
|||||||
|
import { assertEquals, assertExists } from "std/testing/asserts.ts";
|
||||||
import { assertEquals } from "std/testing/asserts.ts";
|
import {
|
||||||
import { createTestUser, createRedemptionCode, cleanup, adminClient, SUPABASE_URL } from "./utils.ts";
|
adminClient,
|
||||||
|
cleanup,
|
||||||
|
createRedemptionCode,
|
||||||
|
createTestUser,
|
||||||
|
SUPABASE_URL,
|
||||||
|
} from "./utils.ts";
|
||||||
|
|
||||||
const FUNCTION_URL = `${SUPABASE_URL}/functions/v1/redeem-code`;
|
const FUNCTION_URL = `${SUPABASE_URL}/functions/v1/redeem-code`;
|
||||||
|
|
||||||
Deno.test("redeem-code: successfully redeems code for user", async () => {
|
Deno.test("redeem-code: successfully redeems code for user", async () => {
|
||||||
const email = `test_redeem_${Date.now()}@example.com`;
|
const email = `test_redeem_${Date.now()}@example.com`;
|
||||||
let userIds: string[] = [];
|
let userIds: string[] = [];
|
||||||
let codeId: string | undefined;
|
let codeId: string | undefined;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// 1. Setup User
|
// 1. Setup User
|
||||||
const user = await createTestUser(email);
|
const user = await createTestUser(email);
|
||||||
userIds = [user.id];
|
userIds = [user.id];
|
||||||
|
|
||||||
// 2. Setup Code
|
// 2. Setup Code
|
||||||
const codeData = await createRedemptionCode();
|
const codeData = await createRedemptionCode();
|
||||||
codeId = codeData.id;
|
codeId = codeData.id;
|
||||||
|
|
||||||
// 3. Call Function
|
// 3. Call Function
|
||||||
const res = await fetch(FUNCTION_URL, {
|
const res = await fetch(FUNCTION_URL, {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: { "Content-Type": "application/json" },
|
headers: { "Content-Type": "application/json" },
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
email,
|
email,
|
||||||
code: codeData.code
|
code: codeData.code,
|
||||||
})
|
}),
|
||||||
});
|
});
|
||||||
|
|
||||||
const data = await res.json();
|
const data = await res.json();
|
||||||
assertEquals(res.status, 200);
|
assertEquals(res.status, 200);
|
||||||
assertEquals(data.success, true);
|
assertEquals(data.success, true);
|
||||||
|
|
||||||
// 4. Verify Profile is Premium
|
// 4. Verify Profile is Premium
|
||||||
const { data: profile } = await adminClient
|
const { data: profile } = await adminClient
|
||||||
.from("profiles")
|
.from("profiles")
|
||||||
.select("is_premium")
|
.select("is_premium")
|
||||||
.eq("id", user.id)
|
.eq("id", user.id)
|
||||||
.single();
|
.single();
|
||||||
|
|
||||||
assertEquals(profile.is_premium, true);
|
|
||||||
|
|
||||||
} finally {
|
assertExists(profile);
|
||||||
await cleanup(userIds);
|
assertEquals(profile.is_premium, true);
|
||||||
if (codeId) await adminClient.from("redemption_codes").delete().eq("id", codeId);
|
} finally {
|
||||||
|
await cleanup(userIds);
|
||||||
|
if (codeId) {
|
||||||
|
await adminClient.from("redemption_codes").delete().eq("id", codeId);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
Reference in new issue
Block a user