mirror of
https://github.com/balzack/databag.git
synced 2025-04-24 02:25:26 +00:00
testing channel removal
This commit is contained in:
parent
cceedb491a
commit
8c65d07309
@ -45,7 +45,7 @@ const getChannel = (subject: string, message: string, revision: number) => {
|
||||
return {
|
||||
id: 'CHAN1',
|
||||
revision: revision,
|
||||
data: {
|
||||
data: revision === 3 ? undefined : {
|
||||
detailRevision: revision,
|
||||
topicRevision: revision,
|
||||
channelSummary: revision !== 1 ? undefined : {
|
||||
@ -119,17 +119,26 @@ const getChannelSummary = (message: string) => {
|
||||
jest.mock('../src/net/fetchUtil', () => {
|
||||
|
||||
const fn = jest.fn().mockImplementation((url: string, options: { method: string, body: string }) => {
|
||||
if (url == 'http://test_url/contact/cards?agent=test_token') {
|
||||
if (url == 'http://test_url/contact/cards?agent=test_token') {
|
||||
return Promise.resolve({ status: 200, json: () => [getCard('A', 1)] });
|
||||
} else if (url == 'http://test_url/contact/cards?agent=test_token&revision=1') {
|
||||
return Promise.resolve({ status: 200, json: () => [getCard('A', 2)] });
|
||||
} else if (url == 'https://URL_A/content/channels?contact=G000A.T000A&viewRevision=1&types=%5B%5D') {
|
||||
} else if (url == 'http://test_url/contact/cards?agent=test_token&revision=2') {
|
||||
return Promise.resolve({ status: 200, json: () => [getCard('A', 3)] });
|
||||
} else if (url == 'https://URL_A/content/channels?contact=G000A.T000A&viewRevision=1&types=%5B%5D' ||
|
||||
url == 'http://test_url/content/channels?agent=test_token&types=%5B%5D') {
|
||||
return Promise.resolve({ status: 200, json: () => [getChannel('test_subject_0', 'test_message_0', 1)] });
|
||||
} else if (url == 'https://URL_A/content/channels?contact=G000A.T000A&viewRevision=1&channelRevision=1&types=%5B%5D') {
|
||||
} else if (url == 'https://URL_A/content/channels?contact=G000A.T000A&viewRevision=1&channelRevision=1&types=%5B%5D' ||
|
||||
url == 'http://test_url/content/channels?agent=test_token&revision=1&types=%5B%5D') {
|
||||
return Promise.resolve({ status: 200, json: () => [getChannel('test_subject_1', 'test_message_1', 2)] });
|
||||
} else if (url == 'https://URL_A/content/channels/CHAN1/detail?contact=G000A.T000A') {
|
||||
} else if (url == 'https://URL_A/content/channels?contact=G000A.T000A&viewRevision=1&channelRevision=2&types=%5B%5D' ||
|
||||
url == 'http://test_url/content/channels?agent=test_token&revision=2&types=%5B%5D') {
|
||||
return Promise.resolve({ status: 200, json: () => [getChannel('test_subject_2', 'test_message_2', 3)] });
|
||||
} else if (url == 'https://URL_A/content/channels/CHAN1/detail?contact=G000A.T000A' ||
|
||||
url == 'http://test_url/content/channels/CHAN1/detail?agent=test_token') {
|
||||
return Promise.resolve({ status: 200, json: () => getChannelDetail('test_subject_1') });
|
||||
} else if (url == 'https://URL_A/content/channels/CHAN1/summary?contact=G000A.T000A') {
|
||||
} else if (url == 'https://URL_A/content/channels/CHAN1/summary?contact=G000A.T000A' ||
|
||||
url == 'http://test_url/content/channels/CHAN1/summary?agent=test_token') {
|
||||
return Promise.resolve({ status: 200, json: () => getChannelSummary('test_message_1') });
|
||||
} else {
|
||||
console.log(url, options.method);
|
||||
@ -148,7 +157,7 @@ class TestStore extends NoStore {
|
||||
const log = new ConsoleLogging();
|
||||
const store = new TestStore();
|
||||
|
||||
test('received content updates', async () => {
|
||||
test('received contact updates', async () => {
|
||||
const cardChannels = new Map<string | null, Channel[]>();
|
||||
const stream = new StreamModule(log, store, null, 'test_guid', 'test_token', 'test_url', false, []);
|
||||
const contact = new ContactModule(log, store, null, 'test_guid', 'test_token', 'test_url', false, [], []);
|
||||
@ -168,6 +177,36 @@ test('received content updates', async () => {
|
||||
await waitFor(() => cardChannels.get('C000A')?.[0].data.subject === 'test_subject_1');
|
||||
await waitFor(() => cardChannels.get('C000A')?.[0].lastTopic.data.message === 'test_message_1');
|
||||
|
||||
await contact.setRevision(3);
|
||||
await waitFor(() => cardChannels.get('C000A')?.length === 0);
|
||||
|
||||
await stream.close();
|
||||
await contact.close();
|
||||
});
|
||||
|
||||
test('received stream updates', async () => {
|
||||
const streamChannels = new Map<string | null, Channel[]>();
|
||||
const stream = new StreamModule(log, store, null, 'test_guid', 'test_token', 'test_url', false, []);
|
||||
const contact = new ContactModule(log, store, null, 'test_guid', 'test_token', 'test_url', false, [], []);
|
||||
const content = new ContentModule(log, null, contact, stream);
|
||||
|
||||
const channelUpdate = ({ channels, cardId }: { channels: Channel[]; cardId: string | null }) => {
|
||||
streamChannels.set(cardId, channels);
|
||||
};
|
||||
content.addChannelListener(channelUpdate);
|
||||
|
||||
await stream.setRevision(1);
|
||||
await waitFor(() => streamChannels.get(null)?.length === 1);
|
||||
await waitFor(() => streamChannels.get(null)?.[0].data.subject === 'test_subject_0');
|
||||
await waitFor(() => streamChannels.get(null)?.[0].lastTopic.data.message === 'test_message_0');
|
||||
|
||||
await stream.setRevision(2);
|
||||
await waitFor(() => streamChannels.get(null)?.[0].data.subject === 'test_subject_1');
|
||||
await waitFor(() => streamChannels.get(null)?.[0].lastTopic.data.message === 'test_message_1');
|
||||
|
||||
await stream.setRevision(3);
|
||||
await waitFor(() => streamChannels.get(null)?.length === 0);
|
||||
|
||||
await stream.close();
|
||||
await contact.close();
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user