Fix add-email preserve identity email state flow
This commit is contained in:
@@ -154,3 +154,77 @@ test('pollCloudMailVerificationCode ignores stale receive mailbox when generator
|
||||
assert.equal(result.code, '246810');
|
||||
assert.deepEqual(api.snapshot().listCalls, ['generated@example.com']);
|
||||
});
|
||||
|
||||
test('fetchCloudMailAddress preserves phone identity through the shared persistence helper', async () => {
|
||||
const persistCalls = [];
|
||||
const setEmailCalls = [];
|
||||
const api = globalThis.MultiPageBackgroundCloudMailProvider.createCloudMailProvider({
|
||||
addLog: async () => {},
|
||||
buildCloudMailHeaders: () => ({}),
|
||||
CLOUD_MAIL_DEFAULT_PAGE_SIZE: 20,
|
||||
CLOUD_MAIL_GENERATOR: 'cloudmail',
|
||||
CLOUD_MAIL_PROVIDER: 'cloudmail',
|
||||
fetchImpl: async (url) => {
|
||||
if (String(url).includes('/api/public/addUser')) {
|
||||
return {
|
||||
ok: true,
|
||||
text: async () => JSON.stringify({ code: 200 }),
|
||||
};
|
||||
}
|
||||
return {
|
||||
ok: true,
|
||||
text: async () => JSON.stringify({ code: 200, data: { token: 'token' } }),
|
||||
};
|
||||
},
|
||||
getCloudMailTokenFromResponse: () => 'token',
|
||||
getState: async () => ({}),
|
||||
joinCloudMailUrl: (baseUrl, path) => `${baseUrl}${path}`,
|
||||
normalizeCloudMailAddress: (value) => String(value || '').trim().toLowerCase(),
|
||||
normalizeCloudMailBaseUrl: (value) => String(value || '').trim(),
|
||||
normalizeCloudMailDomain: (value) => String(value || '').trim(),
|
||||
normalizeCloudMailDomains: (values) => values || [],
|
||||
normalizeCloudMailMailApiMessages: () => [],
|
||||
persistRegistrationEmailState: async (state, email, options) => {
|
||||
persistCalls.push({ state, email, options });
|
||||
},
|
||||
pickVerificationMessageWithTimeFallback: () => ({
|
||||
match: null,
|
||||
usedRelaxedFilters: false,
|
||||
usedTimeFallback: false,
|
||||
}),
|
||||
setEmailState: async (email) => {
|
||||
setEmailCalls.push(email);
|
||||
},
|
||||
setPersistentSettings: async () => {},
|
||||
sleepWithStop: async () => {},
|
||||
throwIfStopped: () => {},
|
||||
});
|
||||
|
||||
const state = {
|
||||
cloudMailBaseUrl: 'https://mail.example.com',
|
||||
cloudMailAdminEmail: 'admin@example.com',
|
||||
cloudMailAdminPassword: 'secret',
|
||||
cloudMailToken: 'token',
|
||||
cloudMailDomain: 'example.com',
|
||||
accountIdentifierType: 'phone',
|
||||
accountIdentifier: '+447780579093',
|
||||
signupPhoneNumber: '+447780579093',
|
||||
};
|
||||
const email = await api.fetchCloudMailAddress(state, {
|
||||
localPart: 'fresh',
|
||||
preserveAccountIdentity: true,
|
||||
});
|
||||
|
||||
assert.equal(email, 'fresh@example.com');
|
||||
assert.deepStrictEqual(setEmailCalls, []);
|
||||
assert.deepStrictEqual(persistCalls, [
|
||||
{
|
||||
state,
|
||||
email: 'fresh@example.com',
|
||||
options: {
|
||||
source: 'generated:cloudmail',
|
||||
preserveAccountIdentity: true,
|
||||
},
|
||||
},
|
||||
]);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user