Fix type error in tests

This commit is contained in:
Ajay
2023-08-03 01:16:57 -04:00
parent dfa4578d28
commit 1dbb393e4d
3 changed files with 6 additions and 6 deletions

View File

@@ -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 parts = licenseKey.split("-");
const code = parts[0]; const code = parts[0];
const givenResult = parts[1]; const givenResult = parts[1];

View File

@@ -26,7 +26,7 @@ let localLicense: string;
const gumroadLicense = gumroad.generateLicense(); const gumroadLicense = gumroad.generateLicense();
const extractLicenseKey = (data: string) => { 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); const match = data.match(regex);
if (!match) throw new Error("Failed to extract license key"); if (!match) throw new Error("Failed to extract license key");
return match[1]; return match[1];
@@ -65,8 +65,8 @@ describe("generateToken test", function() {
it("Should be able to create new local token", function (done) { it("Should be able to create new local token", function (done) {
createAndSaveToken(TokenType.local).then((licenseKey) => { createAndSaveToken(TokenType.local).then((licenseKey) => {
assert.ok(validateLicenseKeyRegex(licenseKey)); assert.ok(validateLicenseKeyRegex(licenseKey[0]));
localLicense = licenseKey; localLicense = licenseKey[0];
done(); done();
}).catch(err => done(err)); }).catch(err => done(err));
}); });

View File

@@ -19,13 +19,13 @@ describe("tokenUtils test", function() {
it("Should be able to create patreon token", function (done) { it("Should be able to create patreon token", function (done) {
if (!config?.patreon) this.skip(); if (!config?.patreon) this.skip();
tokenUtils.createAndSaveToken(tokenUtils.TokenType.patreon, "test_code").then((licenseKey) => { tokenUtils.createAndSaveToken(tokenUtils.TokenType.patreon, "test_code").then((licenseKey) => {
assert.ok(validateToken(licenseKey)); assert.ok(validateToken(licenseKey[0]));
done(); done();
}); });
}); });
it("Should be able to create local token", (done) => { it("Should be able to create local token", (done) => {
tokenUtils.createAndSaveToken(tokenUtils.TokenType.local).then((licenseKey) => { tokenUtils.createAndSaveToken(tokenUtils.TokenType.local).then((licenseKey) => {
assert.ok(validateToken(licenseKey)); assert.ok(validateToken(licenseKey[0]));
done(); done();
}); });
}); });