From 1dbb393e4dc583f6976df8c959e06c8834d42dc6 Mon Sep 17 00:00:00 2001 From: Ajay Date: Thu, 3 Aug 2023 01:16:57 -0400 Subject: [PATCH] Fix type error in tests --- src/routes/verifyToken.ts | 2 +- test/cases/generateVerifyToken.ts | 6 +++--- test/cases/tokenUtils.ts | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/routes/verifyToken.ts b/src/routes/verifyToken.ts index c206377..d68c6ae 100644 --- a/src/routes/verifyToken.ts +++ b/src/routes/verifyToken.ts @@ -30,7 +30,7 @@ export async function verifyTokenRequest(req: VerifyTokenRequest, res: Response) }); } - if (isLocalLicenseKey(licenseKey)) { + if (isLocalLicenseKey(licenseKey) && !licenseKey.startsWith("P")) { const parts = licenseKey.split("-"); const code = parts[0]; const givenResult = parts[1]; diff --git a/test/cases/generateVerifyToken.ts b/test/cases/generateVerifyToken.ts index 6ca5ad1..a4de8e1 100644 --- a/test/cases/generateVerifyToken.ts +++ b/test/cases/generateVerifyToken.ts @@ -26,7 +26,7 @@ let localLicense: string; const gumroadLicense = gumroad.generateLicense(); const extractLicenseKey = (data: string) => { - const regex = /([A-Za-z0-9]{40})/; + const regex = /([A-Za-z0-9-]{5}-[A-Za-z0-9-]{5})/; const match = data.match(regex); if (!match) throw new Error("Failed to extract license key"); return match[1]; @@ -65,8 +65,8 @@ describe("generateToken test", function() { it("Should be able to create new local token", function (done) { createAndSaveToken(TokenType.local).then((licenseKey) => { - assert.ok(validateLicenseKeyRegex(licenseKey)); - localLicense = licenseKey; + assert.ok(validateLicenseKeyRegex(licenseKey[0])); + localLicense = licenseKey[0]; done(); }).catch(err => done(err)); }); diff --git a/test/cases/tokenUtils.ts b/test/cases/tokenUtils.ts index 8ff9076..c9fa472 100644 --- a/test/cases/tokenUtils.ts +++ b/test/cases/tokenUtils.ts @@ -19,13 +19,13 @@ describe("tokenUtils test", function() { it("Should be able to create patreon token", function (done) { if (!config?.patreon) this.skip(); tokenUtils.createAndSaveToken(tokenUtils.TokenType.patreon, "test_code").then((licenseKey) => { - assert.ok(validateToken(licenseKey)); + assert.ok(validateToken(licenseKey[0])); done(); }); }); it("Should be able to create local token", (done) => { tokenUtils.createAndSaveToken(tokenUtils.TokenType.local).then((licenseKey) => { - assert.ok(validateToken(licenseKey)); + assert.ok(validateToken(licenseKey[0])); done(); }); });