diff --git a/src/index.ts b/src/index.ts index befca60..6d500e1 100644 --- a/src/index.ts +++ b/src/index.ts @@ -101,30 +101,29 @@ export interface HcaptchaResponse { * @see {@link HcaptchaResponse} * @see {@link https://docs.hcaptcha.com/#siteverify-error-codes-table} */ -export enum HcaptchaError { +export type HcaptchaError = /** Secret key is missing */ - MissingInputSecret = "missing-input-secret", + | "missing-input-secret" /** Secret key is invalid */ - InvalidInputSecret = "invalid-input-secret", + | "invalid-input-secret" /** User response token is missing */ - MissingInputResponse = "missing-input-response", + | "missing-input-response" /** User response token is invalid */ - InvalidInputResponse = "invalid-input-response", + | "invalid-input-response" /** Site key is invalid */ - InvalidSiteKey = "invalid-sitekey", + | "invalid-sitekey" /** Remote user IP is invalid */ - InvalidRemoteIp = "invalid-remoteip", + | "invalid-remoteip" /** Request is invalid */ - BadRequest = "bad-request", + | "bad-request" /** User response token is invalid or has already been checked */ - InvalidOrAlreadySeenResponse = "invalid-or-already-seen-response", + | "invalid-or-already-seen-response" /** Must use the test site key when using a test verification token */ - NotUsingDummyPassCode = "not-using-dummy-passcode", + | "not-using-dummy-passcode" /** Must use the test secret key when using a test verification token */ - NotUsingDummySecret = "not-using-dummy-secret", + | "not-using-dummy-secret" /** The site key is not associated to the secret key */ - SiteKeySecretMismatch = "sitekey-secret-mismatch", -} + | "sitekey-secret-mismatch"; /** * `RawHcaptchaResponse` represents the raw response to the verification challenge diff --git a/test/index.test.ts b/test/index.test.ts index d95ad9a..bd77b51 100644 --- a/test/index.test.ts +++ b/test/index.test.ts @@ -6,7 +6,7 @@ import FSPersister from "@pollyjs/persister-fs"; import nock from "nock"; import * as path from "path"; import { setupPolly } from "setup-polly-jest"; -import { HcaptchaError, verifyHcaptchaToken } from "../src"; +import { verifyHcaptchaToken } from "../src"; // See https://github.com/gribnoysup/setup-polly-jest/issues/23#issuecomment-890494186 // Polly.register(NodeHttpAdapter); @@ -43,8 +43,8 @@ describe("verifyHcaptchaToken", () => { expect(success).toEqual(false); expect(errorCodes).toEqual([ - HcaptchaError.MissingInputResponse, - HcaptchaError.MissingInputSecret, + "missing-input-response", + "missing-input-secret", ]); expect(res).toMatchSnapshot(); @@ -59,7 +59,7 @@ describe("verifyHcaptchaToken", () => { const { success, errorCodes } = res; expect(success).toEqual(false); - expect(errorCodes).toEqual([HcaptchaError.MissingInputResponse]); + expect(errorCodes).toEqual(["missing-input-response"]); expect(res).toMatchSnapshot(); }); @@ -74,7 +74,7 @@ describe("verifyHcaptchaToken", () => { const { success, errorCodes } = res; expect(success).toEqual(false); - expect(errorCodes).toEqual([HcaptchaError.InvalidInputResponse]); + expect(errorCodes).toEqual(["invalid-input-response"]); expect(res).toMatchSnapshot(); }); @@ -92,7 +92,7 @@ describe("verifyHcaptchaToken", () => { // NOTE: this error is returned by the API // but is not documented in the hCaptcha developer docs - expect(errorCodes).toEqual([HcaptchaError.NotUsingDummySecret]); + expect(errorCodes).toEqual(["not-using-dummy-secret"]); expect(res).toMatchSnapshot({ challengeTimestamp: expect.any(String), @@ -113,7 +113,7 @@ describe("verifyHcaptchaToken", () => { // NOTE: this error is returned by the API // but is not documented in the hCaptcha developer docs - expect(errorCodes).toEqual([HcaptchaError.InvalidSiteKey]); + expect(errorCodes).toEqual(["invalid-sitekey"]); expect(res).toMatchSnapshot(); }); @@ -133,7 +133,7 @@ describe("verifyHcaptchaToken", () => { // NOTE: this error is returned by the API // but is not documented in the hCaptcha developer docs - expect(errorCodes).toEqual([HcaptchaError.InvalidRemoteIp]); + expect(errorCodes).toEqual(["invalid-remoteip"]); expect(res).toMatchSnapshot(); });