Skip to content

Commit

Permalink
test: add timestamp tests for graphql server
Browse files Browse the repository at this point in the history
  • Loading branch information
0xOlias committed Jun 28, 2023
1 parent 9c7441e commit 2ff4426
Showing 1 changed file with 98 additions and 2 deletions.
100 changes: 98 additions & 2 deletions packages/core/src/server/service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ const setup = async ({ userStore }: { userStore: UserStore }) => {
const createTestEntity = async ({ id }: { id: number }) => {
await userStore.create({
modelName: "TestEntity",
timestamp: id,
timestamp: 0,
id: String(id),
data: {
string: String(id),
Expand Down Expand Up @@ -90,7 +90,7 @@ const setup = async ({ userStore }: { userStore: UserStore }) => {
}) => {
await userStore.create({
modelName: "EntityWithBigIntId",
timestamp: Number(id),
timestamp: 0,
id,
data: {
testEntity: testEntityId,
Expand Down Expand Up @@ -1299,3 +1299,99 @@ test("limits and skips together as expected", async (context) => {
await service.teardown();
await userStore.teardown();
});

test("serves singular entity versioned at specified timestamp", async (context) => {
const { userStore } = context;
const { service, gql, createTestEntity } = await setup({ userStore });

await createTestEntity({ id: 1 });
await userStore.update({
modelName: "TestEntity",
timestamp: 10,
id: String(1),
data: {
string: "updated",
},
});

const responseOld = await gql(`
testEntity(id: "1", timestamp: 5) {
id
string
}
`);
expect(responseOld.body.errors).toBe(undefined);
expect(responseOld.statusCode).toBe(200);
const testEntityOld = responseOld.body.data.testEntity;
expect(testEntityOld.string).toBe("1");

const response = await gql(`
testEntity(id: "1", timestamp: 15) {
id
string
}
`);
expect(response.body.errors).toBe(undefined);
expect(response.statusCode).toBe(200);
const testEntity = response.body.data.testEntity;
expect(testEntity.string).toBe("updated");

await service.teardown();
await userStore.teardown();
});

test("serves plural entities versioned at specified timestamp", async (context) => {
const { userStore } = context;
const { service, gql, createTestEntity } = await setup({ userStore });

await createTestEntity({ id: 1 });
await createTestEntity({ id: 2 });

await userStore.update({
modelName: "TestEntity",
timestamp: 10,
id: String(1),
data: {
string: "updated",
},
});
await userStore.update({
modelName: "TestEntity",
timestamp: 15,
id: String(2),
data: {
string: "updated",
},
});

const responseOld = await gql(`
testEntitys(timestamp: 12, orderBy: "int") {
id
string
}
`);
expect(responseOld.body.errors).toBe(undefined);
expect(responseOld.statusCode).toBe(200);
const testEntitysOld = responseOld.body.data.testEntitys;
expect(testEntitysOld).toMatchObject([
{ id: "1", string: "updated" },
{ id: "2", string: "2" },
]);

const response = await gql(`
testEntitys(orderBy: "int") {
id
string
}
`);
expect(response.body.errors).toBe(undefined);
expect(response.statusCode).toBe(200);
const testEntitys = response.body.data.testEntitys;
expect(testEntitys).toMatchObject([
{ id: "1", string: "updated" },
{ id: "2", string: "updated" },
]);

await service.teardown();
await userStore.teardown();
});

0 comments on commit 2ff4426

Please sign in to comment.