Run test matrix without sqs

This commit is contained in:
Dean 2024-05-02 17:09:47 +01:00
parent 56fd28eb54
commit 16e3e1b759
1 changed files with 199 additions and 192 deletions

View File

@ -172,216 +172,223 @@ describe.each([
} }
// Ensure all bindings resolve and perform as expected // Ensure all bindings resolve and perform as expected
describe("bindings", () => { !isSqs &&
let globalUsers: any = [] describe("bindings", () => {
let globalUsers: any = []
const future = new Date(serverTime.getTime()) const future = new Date(serverTime.getTime())
future.setDate(future.getDate() + 30) future.setDate(future.getDate() + 30)
const rows = (currentUser: User) => { const rows = (currentUser: User) => {
return [ return [
{ name: "foo", appointment: "1982-01-05T00:00:00.000Z" }, { name: "foo", appointment: "1982-01-05T00:00:00.000Z" },
{ name: "bar", appointment: "1995-05-06T00:00:00.000Z" }, { name: "bar", appointment: "1995-05-06T00:00:00.000Z" },
{ name: currentUser.firstName, appointment: future.toISOString() }, { name: currentUser.firstName, appointment: future.toISOString() },
{ name: "serverDate", appointment: serverTime.toISOString() }, { name: "serverDate", appointment: serverTime.toISOString() },
{ {
name: "single user, session user", name: "single user, session user",
single_user: JSON.stringify([currentUser]), single_user: JSON.stringify([currentUser]),
}, },
{ name: "single user", single_user: JSON.stringify([globalUsers[0]]) }, {
{ name: "single user",
name: "multi user", single_user: JSON.stringify([globalUsers[0]]),
multi_user: JSON.stringify(globalUsers), },
}, {
{ name: "multi user",
name: "multi user with session user", multi_user: JSON.stringify(globalUsers),
multi_user: JSON.stringify([...globalUsers, currentUser]), },
}, {
] name: "multi user with session user",
} multi_user: JSON.stringify([...globalUsers, currentUser]),
},
]
}
beforeAll(async () => { beforeAll(async () => {
// Set up some global users // Set up some global users
globalUsers = await Promise.all( globalUsers = await Promise.all(
Array(2) Array(2)
.fill(0) .fill(0)
.map(async () => { .map(async () => {
const globalUser = await config.globalUser() const globalUser = await config.globalUser()
const userMedataId = globalUser._id const userMedataId = globalUser._id
? dbCore.generateUserMetadataID(globalUser._id) ? dbCore.generateUserMetadataID(globalUser._id)
: null : null
return { return {
_id: globalUser._id, _id: globalUser._id,
_meta: userMedataId, _meta: userMedataId,
} }
}) })
) )
await createTable({ await createTable({
name: { name: "name", type: FieldType.STRING }, name: { name: "name", type: FieldType.STRING },
appointment: { name: "appointment", type: FieldType.DATETIME }, appointment: { name: "appointment", type: FieldType.DATETIME },
single_user: { single_user: {
name: "single_user", name: "single_user",
type: FieldType.BB_REFERENCE, type: FieldType.BB_REFERENCE,
subtype: BBReferenceFieldSubType.USER, subtype: BBReferenceFieldSubType.USER,
}, },
multi_user: { multi_user: {
name: "multi_user", name: "multi_user",
type: FieldType.BB_REFERENCE, type: FieldType.BB_REFERENCE,
subtype: BBReferenceFieldSubType.USERS, subtype: BBReferenceFieldSubType.USERS,
}, },
})
await createRows([...rows(config.getUser())])
}) })
await createRows([...rows(config.getUser())])
})
// !! Current User is auto generated per run // !! Current User is auto generated per run
it("should return all rows matching the session user firstname", async () => { it("should return all rows matching the session user firstname", async () => {
await expectQuery({ await expectQuery({
equal: { name: "{{ [user].firstName }}" }, equal: { name: "{{ [user].firstName }}" },
}).toContainExactly([ }).toContainExactly([
{ name: config.getUser().firstName, appointment: future.toISOString() }, {
]) name: config.getUser().firstName,
}) appointment: future.toISOString(),
it("should parse the date binding and return all rows after the resolved value", async () => {
await expectQuery({
range: {
appointment: {
low: "{{ [now] }}",
high: "9999-00-00T00:00:00.000Z",
}, },
}, ])
}).toContainExactly([ })
{
name: config.getUser().firstName,
appointment: future.toISOString(),
},
{ name: "serverDate", appointment: serverTime.toISOString() },
])
})
it("should parse the date binding and return all rows before the resolved value", async () => { it("should parse the date binding and return all rows after the resolved value", async () => {
await expectQuery({ await expectQuery({
range: { range: {
appointment: { appointment: {
low: "0000-00-00T00:00:00.000Z", low: "{{ [now] }}",
high: "{{ [now] }}", high: "9999-00-00T00:00:00.000Z",
},
}, },
}, }).toContainExactly([
}).toContainExactly([ {
{ name: "foo", appointment: "1982-01-05T00:00:00.000Z" }, name: config.getUser().firstName,
{ name: "bar", appointment: "1995-05-06T00:00:00.000Z" }, appointment: future.toISOString(),
{ name: "serverDate", appointment: serverTime.toISOString() },
])
})
it("should parse the encoded js snippet. Return rows with appointments up to 1 week in the past", async () => {
const jsBinding = "return snippets.WeeksAgo();"
const encodedBinding = encodeJSBinding(jsBinding)
await expectQuery({
range: {
appointment: {
low: "0000-00-00T00:00:00.000Z",
high: encodedBinding,
}, },
}, { name: "serverDate", appointment: serverTime.toISOString() },
}).toContainExactly([ ])
{ name: "foo", appointment: "1982-01-05T00:00:00.000Z" }, })
{ name: "bar", appointment: "1995-05-06T00:00:00.000Z" },
])
})
it("should parse the encoded js binding. Return rows with appointments 2 weeks in the past", async () => { it("should parse the date binding and return all rows before the resolved value", async () => {
const jsBinding = await expectQuery({
"const currentTime = new Date()\ncurrentTime.setDate(currentTime.getDate()-14);\nreturn currentTime.toISOString();" range: {
const encodedBinding = encodeJSBinding(jsBinding) appointment: {
low: "0000-00-00T00:00:00.000Z",
await expectQuery({ high: "{{ [now] }}",
range: { },
appointment: {
low: "0000-00-00T00:00:00.000Z",
high: encodedBinding,
}, },
}, }).toContainExactly([
}).toContainExactly([ { name: "foo", appointment: "1982-01-05T00:00:00.000Z" },
{ name: "foo", appointment: "1982-01-05T00:00:00.000Z" }, { name: "bar", appointment: "1995-05-06T00:00:00.000Z" },
{ name: "bar", appointment: "1995-05-06T00:00:00.000Z" }, { name: "serverDate", appointment: serverTime.toISOString() },
]) ])
}) })
it("should match a single user row by the session user id", async () => { it("should parse the encoded js snippet. Return rows with appointments up to 1 week in the past", async () => {
await expectQuery({ const jsBinding = "return snippets.WeeksAgo();"
equal: { single_user: "{{ [user]._id }}" }, const encodedBinding = encodeJSBinding(jsBinding)
}).toContainExactly([
{
name: "single user, session user",
single_user: [{ _id: config.getUser()._id }],
},
])
})
it("should match the session user id in a multi user field", async () => { await expectQuery({
await expectQuery({ range: {
contains: { multi_user: ["{{ [user]._id }}"] }, appointment: {
}).toContainExactly([ low: "0000-00-00T00:00:00.000Z",
{ high: encodedBinding,
name: "multi user with session user", },
multi_user: [{ _id: config.getUser()._id }], },
}, }).toContainExactly([
]) { name: "foo", appointment: "1982-01-05T00:00:00.000Z" },
}) { name: "bar", appointment: "1995-05-06T00:00:00.000Z" },
])
})
it("should not match the session user id in a multi user field", async () => { it("should parse the encoded js binding. Return rows with appointments 2 weeks in the past", async () => {
await expectQuery({ const jsBinding =
notContains: { multi_user: ["{{ [user]._id }}"] }, "const currentTime = new Date()\ncurrentTime.setDate(currentTime.getDate()-14);\nreturn currentTime.toISOString();"
notEmpty: { multi_user: true }, const encodedBinding = encodeJSBinding(jsBinding)
}).toContainExactly([
{
name: "multi user",
multi_user: globalUsers.map((user: any) => {
return { _id: user._id }
}),
},
])
})
it("should match the session user id and a user table row id using helpers, user binding and a static user id.", async () => { await expectQuery({
await expectQuery({ range: {
oneOf: { appointment: {
single_user: [ low: "0000-00-00T00:00:00.000Z",
"{{ default [user]._id '_empty_' }}", high: encodedBinding,
globalUsers[0]._id, },
], },
}, }).toContainExactly([
}).toContainExactly([ { name: "foo", appointment: "1982-01-05T00:00:00.000Z" },
{ { name: "bar", appointment: "1995-05-06T00:00:00.000Z" },
name: "single user, session user", ])
single_user: [{ _id: config.getUser()._id }], })
},
{
name: "single user",
single_user: [{ _id: globalUsers[0]._id }],
},
])
})
it("should resolve 'default' helper to '_empty_' when binding resolves to nothing", async () => { it("should match a single user row by the session user id", async () => {
await expectQuery({ await expectQuery({
oneOf: { equal: { single_user: "{{ [user]._id }}" },
single_user: [ }).toContainExactly([
"{{ default [user]._idx '_empty_' }}", {
globalUsers[0]._id, name: "single user, session user",
], single_user: [{ _id: config.getUser()._id }],
}, },
}).toContainExactly([ ])
{ })
name: "single user",
single_user: [{ _id: globalUsers[0]._id }], it("should match the session user id in a multi user field", async () => {
}, await expectQuery({
]) contains: { multi_user: ["{{ [user]._id }}"] },
}).toContainExactly([
{
name: "multi user with session user",
multi_user: [{ _id: config.getUser()._id }],
},
])
})
it("should not match the session user id in a multi user field", async () => {
await expectQuery({
notContains: { multi_user: ["{{ [user]._id }}"] },
notEmpty: { multi_user: true },
}).toContainExactly([
{
name: "multi user",
multi_user: globalUsers.map((user: any) => {
return { _id: user._id }
}),
},
])
})
it("should match the session user id and a user table row id using helpers, user binding and a static user id.", async () => {
await expectQuery({
oneOf: {
single_user: [
"{{ default [user]._id '_empty_' }}",
globalUsers[0]._id,
],
},
}).toContainExactly([
{
name: "single user, session user",
single_user: [{ _id: config.getUser()._id }],
},
{
name: "single user",
single_user: [{ _id: globalUsers[0]._id }],
},
])
})
it("should resolve 'default' helper to '_empty_' when binding resolves to nothing", async () => {
await expectQuery({
oneOf: {
single_user: [
"{{ default [user]._idx '_empty_' }}",
globalUsers[0]._id,
],
},
}).toContainExactly([
{
name: "single user",
single_user: [{ _id: globalUsers[0]._id }],
},
])
})
}) })
})
describe("strings", () => { describe("strings", () => {
beforeAll(async () => { beforeAll(async () => {