|
1 | 1 | import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"; |
2 | 2 |
|
3 | | -import { ConfigurationError, ConfigurationErrorCode } from "../errors/index.js"; |
4 | 3 | import { Auth0Client } from "./client.js"; |
5 | 4 |
|
6 | 5 | describe("Auth0Client", () => { |
@@ -37,73 +36,6 @@ describe("Auth0Client", () => { |
37 | 36 | }); |
38 | 37 |
|
39 | 38 | describe("constructor validation", () => { |
40 | | - it("should throw ConfigurationError when all required options are missing", () => { |
41 | | - expect(() => new Auth0Client()).toThrow(ConfigurationError); |
42 | | - |
43 | | - try { |
44 | | - new Auth0Client(); |
45 | | - } catch (error) { |
46 | | - const configError = error as ConfigurationError; |
47 | | - expect(configError).toBeInstanceOf(ConfigurationError); |
48 | | - expect(configError.code).toBe( |
49 | | - ConfigurationErrorCode.MISSING_REQUIRED_OPTIONS |
50 | | - ); |
51 | | - expect(configError.missingOptions).toContain("domain"); |
52 | | - expect(configError.missingOptions).toContain("clientId"); |
53 | | - expect(configError.missingOptions).toContain("clientAuthentication"); |
54 | | - expect(configError.missingOptions).toContain("appBaseUrl"); |
55 | | - expect(configError.missingOptions).toContain("secret"); |
56 | | - |
57 | | - // Check that error message contains specific text |
58 | | - expect(configError.message).toContain( |
59 | | - "Not all required options where provided" |
60 | | - ); |
61 | | - expect(configError.message).toContain(ENV_VARS.DOMAIN); |
62 | | - expect(configError.message).toContain(ENV_VARS.CLIENT_ID); |
63 | | - expect(configError.message).toContain(ENV_VARS.CLIENT_SECRET); |
64 | | - expect(configError.message).toContain( |
65 | | - ENV_VARS.CLIENT_ASSERTION_SIGNING_KEY |
66 | | - ); |
67 | | - expect(configError.message).toContain(ENV_VARS.APP_BASE_URL); |
68 | | - expect(configError.message).toContain(ENV_VARS.SECRET); |
69 | | - } |
70 | | - }); |
71 | | - |
72 | | - it("should throw ConfigurationError when some required options are missing", () => { |
73 | | - // Provide some but not all required options |
74 | | - const options = { |
75 | | - domain: "example.auth0.com", |
76 | | - clientId: "client_123" |
77 | | - }; |
78 | | - |
79 | | - try { |
80 | | - new Auth0Client(options); |
81 | | - } catch (error) { |
82 | | - const configError = error as ConfigurationError; |
83 | | - expect(configError).toBeInstanceOf(ConfigurationError); |
84 | | - expect(configError.code).toBe( |
85 | | - ConfigurationErrorCode.MISSING_REQUIRED_OPTIONS |
86 | | - ); |
87 | | - // These should be missing |
88 | | - expect(configError.missingOptions).toContain("clientAuthentication"); |
89 | | - expect(configError.missingOptions).toContain("appBaseUrl"); |
90 | | - expect(configError.missingOptions).toContain("secret"); |
91 | | - // These should not be in the missing list |
92 | | - expect(configError.missingOptions).not.toContain("domain"); |
93 | | - expect(configError.missingOptions).not.toContain("clientId"); |
94 | | - |
95 | | - // Error message should only contain instructions for missing options |
96 | | - expect(configError.message).toContain(ENV_VARS.CLIENT_SECRET); |
97 | | - expect(configError.message).toContain( |
98 | | - ENV_VARS.CLIENT_ASSERTION_SIGNING_KEY |
99 | | - ); |
100 | | - expect(configError.message).toContain(ENV_VARS.APP_BASE_URL); |
101 | | - expect(configError.message).toContain(ENV_VARS.SECRET); |
102 | | - expect(configError.message).not.toContain(`Set ${ENV_VARS.DOMAIN}`); |
103 | | - expect(configError.message).not.toContain(`Set ${ENV_VARS.CLIENT_ID}`); |
104 | | - } |
105 | | - }); |
106 | | - |
107 | 39 | it("should accept clientSecret as authentication method", () => { |
108 | 40 | // Set required environment variables with clientSecret |
109 | 41 | process.env[ENV_VARS.DOMAIN] = "env.auth0.com"; |
|
0 commit comments