Skip to content

Commit 97a370a

Browse files
test(mosaic): keep out-of-band changes during a fake session touch (#10453)
1 parent 9607435 commit 97a370a

3 files changed

Lines changed: 28 additions & 4 deletions

File tree

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
---
2+
---

‎packages/mosaic/src/__tests__/feature/fake-fapi-user.feature.test.tsx‎

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { describe, expect, it } from 'vitest';
1+
import { describe, expect, it, onTestFinished, vi } from 'vitest';
22

3-
import { fapiUrl, serveFapi } from './fake-fapi';
4-
import { fapiClient, fapiSession, fapiUser, fapiWeb3Wallet } from './fapi';
3+
import { fapiUrl, serveFapi, verifyEmailOutOfBand } from './fake-fapi';
4+
import { fapiClient, fapiEmailAddress, fapiSession, fapiUser, fapiVerification, fapiWeb3Wallet } from './fapi';
55

66
describe('fake FAPI user updates', () => {
77
it('updates profile fields without clearing omitted identification fields', async () => {
@@ -29,4 +29,26 @@ describe('fake FAPI user updates', () => {
2929
web3_wallets: user.web3_wallets,
3030
});
3131
});
32+
33+
it('keeps a user change made while a session touch is in flight', async () => {
34+
const user = fapiUser({
35+
id: 'user_1',
36+
email_addresses: [fapiEmailAddress({ id: 'idn_1', verification: fapiVerification('email_link') })],
37+
});
38+
const fapi = serveFapi({ client: fapiClient([fapiSession({ id: 'sess_1', user })]) });
39+
const readBody = Request.prototype.text;
40+
const text = vi.spyOn(Request.prototype, 'text').mockImplementation(function (this: Request) {
41+
verifyEmailOutOfBand(fapi, 'idn_1');
42+
return readBody.call(this);
43+
});
44+
onTestFinished(() => text.mockRestore());
45+
46+
const response = await fetch(fapiUrl('/v1/client/sessions/sess_1/touch'), {
47+
method: 'POST',
48+
body: new URLSearchParams({ active_organization_id: '' }),
49+
});
50+
51+
expect(response.ok).toBe(true);
52+
expect(fapi.client.sessions[0]?.user.email_addresses[0]?.verification?.status).toBe('verified');
53+
});
3254
});

‎packages/mosaic/src/__tests__/feature/fake-fapi.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -500,11 +500,11 @@ export function serveFapi(seed: FakeFapiSeed = {}): FakeFapiState {
500500
: missing();
501501
}),
502502
http.post(fapiUrl('/v1/client/sessions/:id/touch'), async ({ params, request }) => {
503+
const body = new URLSearchParams(await request.text());
503504
const session = findSession(state, params.id);
504505
if (!session) {
505506
return missing();
506507
}
507-
const body = new URLSearchParams(await request.text());
508508
const organizationId = body.get('active_organization_id') || null;
509509
const touched = {
510510
...session,

0 commit comments

Comments
 (0)