2025-01-01 22:56:34 -06:00
|
|
|
import {App} from "../../util/app";
|
2024-12-25 16:13:48 -06:00
|
|
|
|
|
|
|
describe('Run', () => {
|
|
|
|
let app: App;
|
|
|
|
|
|
|
|
beforeAll(async () => {
|
|
|
|
app = new App({
|
|
|
|
httpPort: 5000,
|
|
|
|
httpEnable: true,
|
|
|
|
requestBindPort: 5001,
|
|
|
|
publishBindPort: 5002,
|
2024-12-31 12:40:26 -06:00
|
|
|
peerId: 'app-001',
|
2024-12-25 16:13:48 -06:00
|
|
|
});
|
|
|
|
await app.start();
|
|
|
|
});
|
|
|
|
|
|
|
|
afterAll(async () => {
|
|
|
|
await app.stop();
|
|
|
|
});
|
|
|
|
|
2024-12-26 15:59:03 -06:00
|
|
|
it('can put a new user and fetch it', async () => {
|
2024-12-26 16:52:46 -06:00
|
|
|
// Create a new record
|
|
|
|
{
|
|
|
|
const res = await fetch(`${app.apiUrl}/user`, {
|
|
|
|
method: 'PUT',
|
|
|
|
headers: {'Content-Type': 'application/json'},
|
|
|
|
body: JSON.stringify({
|
|
|
|
id: "peon-1",
|
|
|
|
properties: {
|
|
|
|
name: "Peon",
|
|
|
|
age: 263
|
|
|
|
}
|
|
|
|
})
|
|
|
|
});
|
|
|
|
const data = await res.json();
|
|
|
|
expect(data).toMatchObject({
|
2024-12-25 16:13:48 -06:00
|
|
|
id: "peon-1",
|
2024-12-25 19:27:36 -06:00
|
|
|
properties: {
|
|
|
|
name: "Peon",
|
|
|
|
age: 263
|
|
|
|
}
|
2024-12-26 16:52:46 -06:00
|
|
|
});
|
|
|
|
}
|
2024-12-26 15:59:03 -06:00
|
|
|
|
2024-12-26 16:52:46 -06:00
|
|
|
// TODO: Optimistic update and remove this delay
|
2024-12-26 15:59:03 -06:00
|
|
|
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
|
|
|
2024-12-26 16:52:46 -06:00
|
|
|
// Read what we wrote
|
|
|
|
{
|
|
|
|
const res = await fetch(`${app.apiUrl}/user/peon-1`);
|
|
|
|
const data = await res.json();
|
|
|
|
expect(data).toMatchObject({
|
|
|
|
id: "peon-1",
|
|
|
|
properties: {
|
|
|
|
name: "Peon",
|
|
|
|
age: 263
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
// Verify our record is also in the index
|
|
|
|
{
|
|
|
|
const res = await fetch(`${app.apiUrl}/user/ids`);
|
|
|
|
const data = await res.json();
|
|
|
|
expect(data).toMatchObject({ids: [ "peon-1"]});
|
|
|
|
}
|
2024-12-26 15:59:03 -06:00
|
|
|
|
2024-12-25 16:13:48 -06:00
|
|
|
});
|
|
|
|
});
|