mirror of
https://github.com/jjbrunton/Sauci.git
synced 2026-10-31 10: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 } from "std/testing/asserts.ts";
|
||||
import { createTestUser, createRedemptionCode, cleanup, adminClient, SUPABASE_URL } from "./utils.ts";
|
||||
import { assertEquals, assertExists } from "std/testing/asserts.ts";
|
||||
import {
|
||||
adminClient,
|
||||
cleanup,
|
||||
createRedemptionCode,
|
||||
createTestUser,
|
||||
SUPABASE_URL,
|
||||
} from "./utils.ts";
|
||||
|
||||
const FUNCTION_URL = `${SUPABASE_URL}/functions/v1/redeem-code`;
|
||||
|
||||
Deno.test("redeem-code: successfully redeems code for user", async () => {
|
||||
const email = `test_redeem_${Date.now()}@example.com`;
|
||||
let userIds: string[] = [];
|
||||
let codeId: string | undefined;
|
||||
const email = `test_redeem_${Date.now()}@example.com`;
|
||||
let userIds: string[] = [];
|
||||
let codeId: string | undefined;
|
||||
|
||||
try {
|
||||
// 1. Setup User
|
||||
const user = await createTestUser(email);
|
||||
userIds = [user.id];
|
||||
try {
|
||||
// 1. Setup User
|
||||
const user = await createTestUser(email);
|
||||
userIds = [user.id];
|
||||
|
||||
// 2. Setup Code
|
||||
const codeData = await createRedemptionCode();
|
||||
codeId = codeData.id;
|
||||
// 2. Setup Code
|
||||
const codeData = await createRedemptionCode();
|
||||
codeId = codeData.id;
|
||||
|
||||
// 3. Call Function
|
||||
const res = await fetch(FUNCTION_URL, {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({
|
||||
email,
|
||||
code: codeData.code
|
||||
})
|
||||
});
|
||||
// 3. Call Function
|
||||
const res = await fetch(FUNCTION_URL, {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({
|
||||
email,
|
||||
code: codeData.code,
|
||||
}),
|
||||
});
|
||||
|
||||
const data = await res.json();
|
||||
assertEquals(res.status, 200);
|
||||
assertEquals(data.success, true);
|
||||
const data = await res.json();
|
||||
assertEquals(res.status, 200);
|
||||
assertEquals(data.success, true);
|
||||
|
||||
// 4. Verify Profile is Premium
|
||||
const { data: profile } = await adminClient
|
||||
.from("profiles")
|
||||
.select("is_premium")
|
||||
.eq("id", user.id)
|
||||
.single();
|
||||
|
||||
assertEquals(profile.is_premium, true);
|
||||
// 4. Verify Profile is Premium
|
||||
const { data: profile } = await adminClient
|
||||
.from("profiles")
|
||||
.select("is_premium")
|
||||
.eq("id", user.id)
|
||||
.single();
|
||||
|
||||
} finally {
|
||||
await cleanup(userIds);
|
||||
if (codeId) await adminClient.from("redemption_codes").delete().eq("id", codeId);
|
||||
assertExists(profile);
|
||||
assertEquals(profile.is_premium, true);
|
||||
} finally {
|
||||
await cleanup(userIds);
|
||||
if (codeId) {
|
||||
await adminClient.from("redemption_codes").delete().eq("id", codeId);
|
||||
}
|
||||
}
|
||||
});
|
||||
Reference in new issue
Block a user