Skip to content

Commit

Permalink
[IRT-1329] fix: Failing test and improve test readability
Browse files Browse the repository at this point in the history
  • Loading branch information
huggingbot committed May 2, 2024
1 parent 12bd5c5 commit b99310b
Showing 1 changed file with 27 additions and 9 deletions.
36 changes: 27 additions & 9 deletions tests/gating.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,34 +8,45 @@ import { COREKIT_STATUS, WEB3AUTH_NETWORK, WEB3AUTH_NETWORK_TYPE, Web3AuthMPCCor
import { criticalResetAccount, mockLogin } from "./setup";

type TestVariable = {
description: string;
web3AuthNetwork: WEB3AUTH_NETWORK_TYPE;
web3ClientID: string;
uxMode: UX_MODE_TYPE | "nodejs";
manualSync?: boolean;
email: string;
gated?: boolean;
expectedErrorThrown: boolean;
};

const defaultTestEmail = "testEmail1";
const variable: TestVariable[] = [
{ web3AuthNetwork: WEB3AUTH_NETWORK.DEVNET, uxMode: "nodejs", email: defaultTestEmail, web3ClientID: "torus-key-test" },
{
description: "should not be gated when on devnet",
web3AuthNetwork: WEB3AUTH_NETWORK.DEVNET,
uxMode: "nodejs",
email: defaultTestEmail,
web3ClientID: "torus-key-test",
expectedErrorThrown: false,
},
{
description: "should be gated and pass when on mainnet with client id on enterprise plan",
web3AuthNetwork: WEB3AUTH_NETWORK.MAINNET,
uxMode: "nodejs",
email: defaultTestEmail,
web3ClientID: "BJ57yveG_XBLqZUpjtJCnJMrord0AaXpd_9OSy4HzkxpnpPn6Co73h-vR6GEI1VogtW4yMHq13GNPKmVpliFXY0",
expectedErrorThrown: false,
},
{
description: "should be gated and throw an error when on mainnet with client id on growth plan",
web3AuthNetwork: WEB3AUTH_NETWORK.MAINNET,
uxMode: "nodejs",
email: defaultTestEmail,
web3ClientID: "BCriFlI9ihm81N-bc7x6N-xbqwBLuxfRDMmSH87spKH27QTNOPj1W9s2K3-mp9NzXuaRiqxvAGHyuGlXG5wLD1g",
gated: true,
expectedErrorThrown: true,
},
];

variable.forEach((testVariable) => {
const { web3AuthNetwork, uxMode, manualSync, email, web3ClientID: web3AuthClientId, gated } = testVariable;
const { web3AuthNetwork, uxMode, manualSync, email, web3ClientID: web3AuthClientId, expectedErrorThrown } = testVariable;
const coreKitInstance = new Web3AuthMPCCoreKit({
web3AuthClientId,
web3AuthNetwork,
Expand All @@ -46,7 +57,7 @@ variable.forEach((testVariable) => {
manualSync,
});

const testNameSuffix = JSON.stringify(testVariable);
const testNameSuffix = testVariable.description;
test(`#Gating test : ${testNameSuffix}`, async (t) => {
t.before(async function () {
if (coreKitInstance.status === COREKIT_STATUS.INITIALIZED) await criticalResetAccount(coreKitInstance);
Expand All @@ -63,7 +74,10 @@ variable.forEach((testVariable) => {
try {
await coreKitInstance.init({ handleRedirectResult: false });
} catch (error) {
if (!gated) throw error;
if (!expectedErrorThrown) {
// Unexpected error
throw error;
}
}
try {
await coreKitInstance.loginWithJWT({
Expand All @@ -72,9 +86,13 @@ variable.forEach((testVariable) => {
idToken,
});
} catch (error) {
if (gated) {
// if result should gated but error message is not "MPC Core Kit not initialized"
if (!((error as Error).message as string).includes("MPC Core Kit not initialized")) {
if (expectedErrorThrown) {
// If we expect an error, check the error message to see if it is the expected error
if (
!((error as Error).message as string).includes(
"The MPC Core Kit is not initialized. Please ensure you call the 'init()' method to initialize the kit properly before attempting any operations."
)
) {
throw error;
}
}
Expand Down

0 comments on commit b99310b

Please sign in to comment.