Files
gods-eye-view/src/keySetupOAuthFailure.test.mjs
T
German KhokhlovandClaude Opus 5.5 20f4cf3763 i18n: fix the LGTM review findings and tidy the branch texts
- i18n scanner: lastError sink, no false sinks on defaults and ternaries
- shared src/i18n/marker.js for modules that only mark strings
- wind field messages move to wind/fields.js; CITY_POIS imports from cityPois.js
- drop review IDs, change history and stale references from comments and docs

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-16 21:00:28 +04:00

54 lines
2.0 KiB
JavaScript

// A failed ChatGPT OAuth check whose only reason is our own fallback sentence
// shows it alone; a server-sent reason keeps the «OAuth check failed» wrapper.
import test from 'node:test';
import assert from 'node:assert/strict';
import { oauthCheckFailureText, waitForChatGptOAuth } from './keySetup.js';
import { setLocale } from './i18n/index.js';
const failWith = (payload, ok = true) =>
waitForChatGptOAuth({
fetchImpl: async () => ({ ok, json: async () => payload }),
sleep: () => assert.fail('failed login must stop polling'),
}).then(
() => assert.fail('expected a rejection'),
(error) => error,
);
test('a fallback-only OAuth failure is shown without the wrapper in every locale', async (t) => {
t.after(() => setLocale('en'));
const expected = {
en: 'Could not check ChatGPT sign-in. Try again.',
ru: 'Не удалось проверить вход в ChatGPT. Попробуйте ещё раз.',
es: 'No se pudo comprobar el inicio de sesión de ChatGPT. Inténtalo de nuevo.',
};
for (const [locale, text] of Object.entries(expected)) {
setLocale(locale);
const loginFailed = await failWith({ available: false, loginFailed: true });
assert.equal(oauthCheckFailureText(loginFailed), text);
const httpFailed = await failWith({}, false);
assert.equal(oauthCheckFailureText(httpFailed), text);
}
});
test('a server-sent or network OAuth failure keeps the «OAuth check failed» wrapper', async (t) => {
t.after(() => setLocale('en'));
setLocale('en');
const server = await failWith({
loginFailed: true,
error: 'Sign-in is local only.',
});
assert.equal(
oauthCheckFailureText(server),
'OAuth check failed: Sign-in is local only.',
);
assert.equal(
oauthCheckFailureText(new TypeError('Failed to fetch')),
'OAuth check failed: Failed to fetch',
);
setLocale('ru');
assert.match(
oauthCheckFailureText(server),
/^Не удалось проверить OAuth: Sign-in is local only\.$/,
);
});