2024-12-25 19:27:36 -06:00
|
|
|
import Debug from 'debug';
|
2024-12-25 19:32:02 -06:00
|
|
|
import {App} from '../../util/app';
|
2024-12-25 19:27:36 -06:00
|
|
|
const debug = Debug('test:two');
|
2024-12-25 17:24:18 -06:00
|
|
|
|
|
|
|
describe('Run', () => {
|
|
|
|
const apps: App[] = [];
|
|
|
|
|
|
|
|
beforeAll(async () => {
|
|
|
|
apps[0] = new App({
|
|
|
|
httpEnable: true,
|
2024-12-25 19:27:36 -06:00
|
|
|
peerId: 'app0',
|
2024-12-25 17:24:18 -06:00
|
|
|
});
|
|
|
|
apps[1] = new App({
|
|
|
|
httpEnable: true,
|
2024-12-25 19:27:36 -06:00
|
|
|
peerId: 'app1',
|
2024-12-25 17:24:18 -06:00
|
|
|
});
|
2024-12-25 19:27:36 -06:00
|
|
|
apps[0].config.seedPeers.push(apps[1].myRequestAddr);
|
|
|
|
apps[1].config.seedPeers.push(apps[0].myRequestAddr);
|
2024-12-25 17:24:18 -06:00
|
|
|
|
|
|
|
await Promise.all(apps.map((app) => app.start()));
|
|
|
|
});
|
|
|
|
|
|
|
|
afterAll(async () => {
|
|
|
|
await Promise.all(apps.map((app) => app.stop()));
|
|
|
|
});
|
|
|
|
|
|
|
|
it('can create a record on node 0 and read it on node 1', async () => {
|
2024-12-25 19:27:36 -06:00
|
|
|
debug('apps[0].apiUrl', apps[0].apiUrl);
|
|
|
|
debug('apps[1].apiUrl', apps[1].apiUrl);
|
|
|
|
|
2024-12-26 15:59:03 -06:00
|
|
|
const res = await fetch(`${apps[0].apiUrl}/user`, {
|
2024-12-25 17:24:18 -06:00
|
|
|
method: 'PUT',
|
|
|
|
headers: {'Content-Type': 'application/json'},
|
|
|
|
body: JSON.stringify({
|
|
|
|
id: "peon-1",
|
2024-12-25 19:27:36 -06:00
|
|
|
properties: {
|
|
|
|
name: "Peon",
|
|
|
|
age: 263
|
|
|
|
}
|
2024-12-25 17:24:18 -06:00
|
|
|
})
|
|
|
|
});
|
|
|
|
const data = await res.json();
|
|
|
|
expect(data).toMatchObject({
|
2024-12-25 19:27:36 -06:00
|
|
|
id: "peon-1",
|
2024-12-25 17:24:18 -06:00
|
|
|
properties: {
|
|
|
|
name: "Peon",
|
|
|
|
age: 263
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2024-12-25 17:32:20 -06:00
|
|
|
await new Promise((resolve) => setTimeout(resolve, 100));
|
2024-12-25 17:24:18 -06:00
|
|
|
|
2024-12-26 15:59:03 -06:00
|
|
|
const res2 = await fetch(`${apps[1].apiUrl}/user/peon-1`);
|
2024-12-25 17:24:18 -06:00
|
|
|
const data2 = await res2.json();
|
2024-12-25 19:27:36 -06:00
|
|
|
debug('data2', data2);
|
2024-12-25 17:24:18 -06:00
|
|
|
expect(data2).toMatchObject({
|
2024-12-25 19:27:36 -06:00
|
|
|
id: "peon-1",
|
2024-12-25 17:24:18 -06:00
|
|
|
properties: {
|
|
|
|
name: "Peon",
|
|
|
|
age: 263
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
});
|