mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-05 02:14:05 +00:00
fix(mail-ingest): make the own address once when two views ask for it together
The first look at the settings made the address outside a transaction and always revoked the live one, so two requests at once could leave a view showing a revoked address. It is now checked and made in one transaction and never replaces an address it finds.
This commit is contained in:
@@ -15,7 +15,7 @@ import { MailIngestSettingsService } from '../../../../src/nest/mail-ingest/mail
|
||||
import { MailIngestModule } from '../../../../src/nest/mail-ingest/mail-ingest.module';
|
||||
import { PermissionsService } from '../../../../src/nest/permissions/permissions.service';
|
||||
import { createSnapshotTestDb } from '../../../helpers/db-mock';
|
||||
import { deleteRows, findRow } from '../../../helpers/factories/rows';
|
||||
import { countRows, deleteRows, findRow } from '../../../helpers/factories/rows';
|
||||
import { setAppSetting } from '../../../helpers/factories/settings';
|
||||
import { addTripMember, makeTrip } from '../../../helpers/factories/trips';
|
||||
import { makeUser } from '../../../helpers/factories/users';
|
||||
@@ -87,6 +87,18 @@ describe('a person’s own address', () => {
|
||||
expect(await addresses().ownAddress(user.id)).toBeNull();
|
||||
});
|
||||
|
||||
it('is made once when two views look at it first at the same time, and both show the one that works', async () => {
|
||||
const { user } = await makeUser(orm());
|
||||
const [a, b] = await Promise.all([
|
||||
addresses().ownAddressForCard(user.id, true),
|
||||
addresses().ownAddressForCard(user.id, true),
|
||||
]);
|
||||
expect(a?.address).toBeTruthy();
|
||||
expect(b?.address).toBe(a?.address);
|
||||
expect(await countRows(orm(), MailIngestAddresses, { user_id: user.id })).toBe(1);
|
||||
expect((await addresses().resolveAll([a?.address ?? '']))[0]?.user_id).toBe(user.id);
|
||||
});
|
||||
|
||||
it('takes no mail while its person has the import off', async () => {
|
||||
const { user } = await makeUser(orm());
|
||||
const own = await addresses().renewOwn(user.id);
|
||||
|
||||
Reference in New Issue
Block a user