From 19270adef8a0a18a9ed54b5ead76472bbf6471bc Mon Sep 17 00:00:00 2001 From: Maurice Date: Thu, 26 Nov 2026 22:26:58 +0100 Subject: [PATCH] test(oauth): read the granted code without non-null assertions --- server/tests/unit/nest/oauth.service.test.ts | 30 +++++++++++--------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/server/tests/unit/nest/oauth.service.test.ts b/server/tests/unit/nest/oauth.service.test.ts index ce6228acf..b576cdb9c 100644 --- a/server/tests/unit/nest/oauth.service.test.ts +++ b/server/tests/unit/nest/oauth.service.test.ts @@ -454,20 +454,22 @@ describe('createAuthCode + consumeAuthCode', () => { it('a code mints tokens only while the password it was granted under holds', async () => { const { user } = createUser(testDb); const created = await makeClient(user.id); - const clientId = created.client!.client_id as string; - const grant = async () => - (await consumeAuthCode( - (await createAuthCode({ - passwordVersion: 0, - clientId, - userId: user.id, - redirectUri: 'https://example.com/callback', - scopes: ['trips:read'], - resource: null, - codeChallenge: 'abc123', - codeChallengeMethod: 'S256', - }))!, - ))!; + const clientId = String(created.client?.client_id); + const grant = async () => { + const code = await createAuthCode({ + passwordVersion: 0, + clientId, + userId: user.id, + redirectUri: 'https://example.com/callback', + scopes: ['trips:read'], + resource: null, + codeChallenge: 'abc123', + codeChallengeMethod: 'S256', + }); + const pending = code ? await consumeAuthCode(code) : null; + if (!pending) throw new Error('the code was not stored'); + return pending; + }; const kept = await svc.issueTokensForCode(await grant()); expect(kept?.access_token).toEqual(expect.any(String));