Migrate schema to service ids

This commit is contained in:
Fedor Indutny 2023-08-16 22:54:39 +02:00 committed by Jamie Kyle
parent 71958f8a01
commit 8b0da36caa
258 changed files with 4795 additions and 2613 deletions

View file

@ -3,11 +3,14 @@
import { assert } from 'chai';
import { generateAci } from '../../types/ServiceId';
import type { ConversationType } from '../../state/ducks/conversations';
import { MemberRepository } from '../../quill/memberRepository';
import { getDefaultConversationWithUuid } from '../../test-both/helpers/getDefaultConversation';
import { getDefaultConversationWithServiceId } from '../../test-both/helpers/getDefaultConversation';
const memberMahershala: ConversationType = getDefaultConversationWithUuid({
const UNKNOWN_SERVICE_ID = generateAci();
const memberMahershala: ConversationType = getDefaultConversationWithServiceId({
id: '555444',
title: 'Pal',
firstName: 'Mahershala',
@ -19,7 +22,7 @@ const memberMahershala: ConversationType = getDefaultConversationWithUuid({
areWeAdmin: false,
});
const memberShia: ConversationType = getDefaultConversationWithUuid({
const memberShia: ConversationType = getDefaultConversationWithServiceId({
id: '333222',
title: 'Buddy',
firstName: 'Shia',
@ -33,7 +36,7 @@ const memberShia: ConversationType = getDefaultConversationWithUuid({
const members: Array<ConversationType> = [memberMahershala, memberShia];
const singleMember: ConversationType = getDefaultConversationWithUuid({
const singleMember: ConversationType = getDefaultConversationWithServiceId({
id: '666777',
title: 'The Guy',
firstName: 'Jeff',
@ -70,24 +73,28 @@ describe('MemberRepository', () => {
it('returns undefined when it does not have the member', () => {
const memberRepository = new MemberRepository(members);
assert.isUndefined(memberRepository.getMemberById('nope'));
assert.isUndefined(memberRepository.getMemberById(UNKNOWN_SERVICE_ID));
});
});
describe('#getMemberByUuid', () => {
it('returns undefined when there is no search uuid', () => {
describe('#getMemberByServiceId', () => {
it('returns undefined when there is no search serviceId', () => {
const memberRepository = new MemberRepository(members);
assert.isUndefined(memberRepository.getMemberByUuid());
assert.isUndefined(memberRepository.getMemberByServiceId());
});
it('returns a matched member', () => {
const memberRepository = new MemberRepository(members);
assert.isDefined(memberRepository.getMemberByUuid(memberMahershala.uuid));
assert.isDefined(
memberRepository.getMemberByServiceId(memberMahershala.serviceId)
);
});
it('returns undefined when it does not have the member', () => {
const memberRepository = new MemberRepository(members);
assert.isUndefined(memberRepository.getMemberByUuid('nope'));
assert.isUndefined(
memberRepository.getMemberByServiceId(UNKNOWN_SERVICE_ID)
);
});
});

View file

@ -5,10 +5,14 @@ import { assert } from 'chai';
import type { RefObject } from 'react';
import Delta from 'quill-delta';
import type { AciString } from '../../../types/ServiceId';
import { generateAci } from '../../../types/ServiceId';
import { matchMention } from '../../../quill/mentions/matchers';
import { MemberRepository } from '../../../quill/memberRepository';
import type { ConversationType } from '../../../state/ducks/conversations';
import { getDefaultConversationWithUuid } from '../../../test-both/helpers/getDefaultConversation';
import { getDefaultConversationWithServiceId } from '../../../test-both/helpers/getDefaultConversation';
const ACI_1 = generateAci();
class FakeTokenList<T> extends Array<T> {
constructor(elements: Array<T>) {
@ -38,7 +42,7 @@ const createMockMentionBlotElement = (
dataset: Record<string, string>
): HTMLElement => createMockElement('mention-blot', dataset);
const memberMahershala: ConversationType = getDefaultConversationWithUuid({
const memberMahershala: ConversationType = getDefaultConversationWithServiceId({
id: '555444',
title: 'Mahershala Ali',
firstName: 'Mahershala',
@ -49,7 +53,7 @@ const memberMahershala: ConversationType = getDefaultConversationWithUuid({
areWeAdmin: false,
});
const memberShia: ConversationType = getDefaultConversationWithUuid({
const memberShia: ConversationType = getDefaultConversationWithServiceId({
id: '333222',
title: 'Shia LaBeouf',
firstName: 'Shia',
@ -69,7 +73,7 @@ const memberRepositoryRef: RefObject<MemberRepository> = {
const matcher = matchMention(memberRepositoryRef);
type Mention = {
uuid: string;
aci: AciString;
title: string;
};
@ -107,10 +111,10 @@ describe('matchMention', () => {
const { insert, attributes } = op;
if (isMention(insert)) {
const { title, uuid } = insert.mention;
const { title, aci } = insert.mention;
assert.equal(title, memberMahershala.title);
assert.equal(uuid, memberMahershala.uuid);
assert.equal(aci, memberMahershala.serviceId);
assert.deepEqual(existingAttributes, attributes, 'attributes');
} else {
@ -121,7 +125,7 @@ describe('matchMention', () => {
it('handles an MentionBlot from clipboard', () => {
const result = matcher(
createMockMentionBlotElement({
uuid: memberMahershala.uuid || '',
aci: memberMahershala.serviceId || '',
title: memberMahershala.title,
}),
EMPTY_DELTA,
@ -135,10 +139,10 @@ describe('matchMention', () => {
const { insert } = op;
if (isMention(insert)) {
const { title, uuid } = insert.mention;
const { title, aci } = insert.mention;
assert.equal(title, memberMahershala.title);
assert.equal(uuid, memberMahershala.uuid);
assert.equal(aci, memberMahershala.serviceId);
} else {
assert.fail('insert is invalid');
}
@ -170,7 +174,7 @@ describe('matchMention', () => {
it('converts a missing MentionBlot to string', () => {
const result = matcher(
createMockMentionBlotElement({
uuid: 'florp',
aci: ACI_1,
title: 'Nonexistent',
}),
EMPTY_DELTA,

View file

@ -38,10 +38,10 @@ describe('getDeltaToRemoveStaleMentions', () => {
const originalOps = [
{
insert: {
mention: { uuid: SERVICE_ID_3, title: 'Klaus' },
mention: { aci: SERVICE_ID_3, title: 'Klaus' },
},
},
{ insert: { mention: { uuid: SERVICE_ID_1, title: 'Werner' } } },
{ insert: { mention: { aci: SERVICE_ID_1, title: 'Werner' } } },
];
const { ops } = getDeltaToRemoveStaleMentions(originalOps, memberUuids);
@ -285,7 +285,7 @@ describe('getTextAndRangesFromOps', () => {
{
insert: {
mention: {
uuid: SERVICE_ID_1,
aci: SERVICE_ID_1,
title: '@fred',
},
},
@ -296,7 +296,7 @@ describe('getTextAndRangesFromOps', () => {
assert.deepEqual(bodyRanges, [
{
length: 1,
mentionUuid: SERVICE_ID_1,
mentionAci: SERVICE_ID_1,
replacementText: '@fred',
start: 15,
},
@ -310,7 +310,7 @@ describe('getTextAndRangesFromOps', () => {
{
insert: {
mention: {
uuid: SERVICE_ID_1,
aci: SERVICE_ID_1,
title: '@fred',
},
},
@ -321,7 +321,7 @@ describe('getTextAndRangesFromOps', () => {
assert.deepEqual(bodyRanges, [
{
length: 1,
mentionUuid: SERVICE_ID_1,
mentionAci: SERVICE_ID_1,
replacementText: '@fred',
start: 0,
},
@ -334,7 +334,7 @@ describe('getTextAndRangesFromOps', () => {
{
insert: {
mention: {
uuid: SERVICE_ID_1,
aci: SERVICE_ID_1,
title: '@fred',
},
},
@ -346,7 +346,7 @@ describe('getTextAndRangesFromOps', () => {
assert.deepEqual(bodyRanges, [
{
length: 1,
mentionUuid: SERVICE_ID_1,
mentionAci: SERVICE_ID_1,
replacementText: '@fred',
start: 6,
},
@ -366,7 +366,7 @@ describe('getTextAndRangesFromOps', () => {
{
insert: {
mention: {
uuid: SERVICE_ID_4,
aci: SERVICE_ID_4,
title: '@alice',
},
},
@ -425,7 +425,7 @@ describe('getTextAndRangesFromOps', () => {
{
start: 5,
length: 1,
mentionUuid: SERVICE_ID_4,
mentionAci: SERVICE_ID_4,
replacementText: '@alice',
},
{
@ -509,7 +509,7 @@ describe('getTextAndRangesFromOps', () => {
{
insert: {
mention: {
uuid: SERVICE_ID_4,
aci: SERVICE_ID_4,
title: '@alice',
},
},
@ -524,7 +524,7 @@ describe('getTextAndRangesFromOps', () => {
{
start: 0,
length: 1,
mentionUuid: SERVICE_ID_4,
mentionAci: SERVICE_ID_4,
replacementText: '@alice',
},
{
@ -549,7 +549,7 @@ describe('getDeltaToRestartMention', () => {
{
insert: {
mention: {
uuid: SERVICE_ID_2,
aci: SERVICE_ID_2,
title: '@sam',
},
},
@ -560,7 +560,7 @@ describe('getDeltaToRestartMention', () => {
{
insert: {
mention: {
uuid: SERVICE_ID_1,
aci: SERVICE_ID_1,
title: '@fred',
},
},