@jskit-ai/auth-web 0.1.250 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,16 @@
1
+ import assert from "node:assert/strict";
2
+ import path from "node:path";
3
+ import test from "node:test";
4
+ import { fileURLToPath } from "node:url";
5
+ import { evaluateI18nCatalogContract } from "../../../tooling/test-support/i18nCatalogContract.mjs";
6
+
7
+ const TEST_DIRECTORY = path.dirname(fileURLToPath(import.meta.url));
8
+ const REPO_ROOT = path.resolve(TEST_DIRECTORY, "..", "..", "..");
9
+
10
+ test("auth-web English catalog matches its source", () => {
11
+ const { problems } = evaluateI18nCatalogContract({
12
+ repoRoot: REPO_ROOT,
13
+ packageDir: path.join(REPO_ROOT, "packages", "auth-web")
14
+ });
15
+ assert.deepEqual(problems, []);
16
+ });
@@ -281,3 +281,17 @@ test("useLoginViewActions includes invitation context when registering from an i
281
281
  }
282
282
  ]);
283
283
  });
284
+
285
+ test("OAuth buttons name their provider in the sign-in sentence", () => {
286
+ const state = createMinimalLoginViewState();
287
+ const actions = useLoginViewActions({ state, validation: {}, queryClient: {}, errorRuntime: { report() {} } });
288
+ const github = { id: "github", label: "GitHub" };
289
+
290
+ assert.equal(actions.oauthProviderButtonLabel(github), "Continue with GitHub");
291
+ assert.equal(actions.oauthProviderButtonLabel({}), "Continue with OAuth provider");
292
+ state.showRememberedAccount.value = true;
293
+ state.rememberedAccountDisplayName.value = "Ada";
294
+ assert.equal(actions.oauthProviderButtonLabel(github), "Continue with GitHub as Ada");
295
+ state.isRegister.value = true;
296
+ assert.equal(actions.oauthProviderButtonLabel(github), "Register with GitHub");
297
+ });
@@ -1,5 +1,7 @@
1
1
  import assert from "node:assert/strict";
2
2
  import test from "node:test";
3
+ import { createI18n } from "vue-i18n";
4
+ import { registerJskitMessages, setJskitI18n } from "@jskit-ai/kernel/client";
3
5
  import {
4
6
  completeOAuthCallbackFromCurrentLocation,
5
7
  completeOAuthCallbackFromUrl,
@@ -22,6 +24,8 @@ test("readOAuthCallbackParamsFromUrl reads query and hash callback params", () =
22
24
  hasSessionPair: false,
23
25
  errorCode: "",
24
26
  errorDescription: "",
27
+ errorDescriptionCode: "",
28
+ errorDescriptionParams: {},
25
29
  provider: "google",
26
30
  returnTo: "/w/acme"
27
31
  }
@@ -38,6 +42,8 @@ test("readOAuthCallbackParamsFromUrl reads query and hash callback params", () =
38
42
  hasSessionPair: true,
39
43
  errorCode: "",
40
44
  errorDescription: "",
45
+ errorDescriptionCode: "",
46
+ errorDescriptionParams: {},
41
47
  provider: "",
42
48
  returnTo: "/home"
43
49
  }
@@ -113,6 +119,30 @@ test("completeOAuthCallbackFromUrl reports callback errors without issuing a req
113
119
  assert.equal(result.errorMessage, "Provider denied access");
114
120
  });
115
121
 
122
+ test("a sign-in error the server explained by redirect shows in the user's language", async (t) => {
123
+ registerJskitMessages({ jskit: { auth: { example: { unavailable: "Sign-in with {provider} is unavailable." } } } });
124
+ setJskitI18n(createI18n({
125
+ legacy: false,
126
+ locale: "it",
127
+ messages: { it: { jskit: { auth: { example: { unavailable: "Accesso con {provider} non disponibile." } } } } }
128
+ }));
129
+ t.after(() => setJskitI18n(null));
130
+ const explained = new URLSearchParams({
131
+ error: "sign_in_unavailable",
132
+ error_description: "Sign-in with Acme is unavailable.",
133
+ error_code: "auth.example.unavailable",
134
+ error_params: JSON.stringify({ provider: "Acme" })
135
+ });
136
+
137
+ const translated = await completeOAuthCallbackFromUrl({ url: `/auth/login?${explained}` });
138
+ assert.equal(translated.errorMessage, "Accesso con Acme non disponibile.");
139
+
140
+ // An app's own sentence under that code stays as the server sent it.
141
+ explained.set("error_description", "Ask your administrator to enable Acme.");
142
+ const asSent = await completeOAuthCallbackFromUrl({ url: `/auth/login?${explained}` });
143
+ assert.equal(asSent.errorMessage, "Ask your administrator to enable Acme.");
144
+ });
145
+
116
146
  test("completeOAuthCallbackFromUrl reports missing providers for code callbacks", async () => {
117
147
  const result = await completeOAuthCallbackFromUrl({
118
148
  url: "/auth/login?code=abc",