|
1 | | -import { describe, expect, it } from 'vitest'; |
| 1 | +import { describe, expect, it, onTestFinished, vi } from 'vitest'; |
2 | 2 |
|
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'; |
5 | 5 |
|
6 | 6 | describe('fake FAPI user updates', () => { |
7 | 7 | it('updates profile fields without clearing omitted identification fields', async () => { |
@@ -29,4 +29,26 @@ describe('fake FAPI user updates', () => { |
29 | 29 | web3_wallets: user.web3_wallets, |
30 | 30 | }); |
31 | 31 | }); |
| 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 | + }); |
32 | 54 | }); |
0 commit comments