Refactored out config changes and now excluding on the affected SQS/Multiuser tests
This commit is contained in:
parent
c4807a8861
commit
04588711e2
|
@ -68,7 +68,7 @@ describe("check the applications endpoints", () => {
|
||||||
|
|
||||||
describe("check the tables endpoints", () => {
|
describe("check the tables endpoints", () => {
|
||||||
it("should allow retrieving tables through search", async () => {
|
it("should allow retrieving tables through search", async () => {
|
||||||
await config.createApp({ appName: "new app 1" })
|
await config.createApp("new app 1")
|
||||||
table = await config.upsertTable()
|
table = await config.upsertTable()
|
||||||
const res = await makeRequest("post", "/tables/search")
|
const res = await makeRequest("post", "/tables/search")
|
||||||
expect(res).toSatisfyApiSpec()
|
expect(res).toSatisfyApiSpec()
|
||||||
|
|
|
@ -179,173 +179,178 @@ describe.each([
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ensure all bindings resolve and perform as expected
|
// Ensure all bindings resolve and perform as expected
|
||||||
!isSqs &&
|
describe("bindings", () => {
|
||||||
describe("bindings", () => {
|
let globalUsers: any = []
|
||||||
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",
|
name: "single user",
|
||||||
single_user: JSON.stringify([globalUsers[0]]),
|
single_user: JSON.stringify([globalUsers[0]]),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "multi user",
|
name: "multi user",
|
||||||
multi_user: JSON.stringify(globalUsers),
|
multi_user: JSON.stringify(globalUsers),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "multi user with session user",
|
name: "multi user with session user",
|
||||||
multi_user: JSON.stringify([...globalUsers, currentUser]),
|
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,
|
name: config.getUser().firstName,
|
||||||
appointment: future.toISOString(),
|
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 after the resolved value", async () => {
|
it("should parse the date binding and return all rows before the resolved value", async () => {
|
||||||
await expectQuery({
|
await expectQuery({
|
||||||
range: {
|
range: {
|
||||||
appointment: {
|
appointment: {
|
||||||
low: "{{ [now] }}",
|
low: "0000-00-00T00:00:00.000Z",
|
||||||
high: "9999-00-00T00:00:00.000Z",
|
high: "{{ [now] }}",
|
||||||
},
|
|
||||||
},
|
},
|
||||||
}).toContainExactly([
|
},
|
||||||
{
|
}).toContainExactly([
|
||||||
name: config.getUser().firstName,
|
{ name: "foo", appointment: "1982-01-05T00:00:00.000Z" },
|
||||||
appointment: future.toISOString(),
|
{ name: "bar", appointment: "1995-05-06T00:00:00.000Z" },
|
||||||
|
{ 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 date binding and return all rows before the resolved value", async () => {
|
it("should parse the encoded js binding. Return rows with appointments 2 weeks in the past", async () => {
|
||||||
await expectQuery({
|
const jsBinding =
|
||||||
range: {
|
"const currentTime = new Date()\ncurrentTime.setDate(currentTime.getDate()-14);\nreturn currentTime.toISOString();"
|
||||||
appointment: {
|
const encodedBinding = encodeJSBinding(jsBinding)
|
||||||
low: "0000-00-00T00:00:00.000Z",
|
|
||||||
high: "{{ [now] }}",
|
await expectQuery({
|
||||||
},
|
range: {
|
||||||
|
appointment: {
|
||||||
|
low: "0000-00-00T00:00:00.000Z",
|
||||||
|
high: encodedBinding,
|
||||||
},
|
},
|
||||||
}).toContainExactly([
|
},
|
||||||
{ name: "foo", appointment: "1982-01-05T00:00:00.000Z" },
|
}).toContainExactly([
|
||||||
{ name: "bar", appointment: "1995-05-06T00:00:00.000Z" },
|
{ name: "foo", appointment: "1982-01-05T00:00:00.000Z" },
|
||||||
{ name: "serverDate", appointment: serverTime.toISOString() },
|
{ name: "bar", appointment: "1995-05-06T00:00:00.000Z" },
|
||||||
])
|
])
|
||||||
})
|
})
|
||||||
|
|
||||||
it("should parse the encoded js snippet. Return rows with appointments up to 1 week in the past", async () => {
|
it("should match a single user row by the session user id", async () => {
|
||||||
const jsBinding = "return snippets.WeeksAgo();"
|
await expectQuery({
|
||||||
const encodedBinding = encodeJSBinding(jsBinding)
|
equal: { single_user: "{{ [user]._id }}" },
|
||||||
|
}).toContainExactly([
|
||||||
await expectQuery({
|
{
|
||||||
range: {
|
name: "single user, session user",
|
||||||
appointment: {
|
single_user: [{ _id: config.getUser()._id }],
|
||||||
low: "0000-00-00T00:00:00.000Z",
|
},
|
||||||
high: encodedBinding,
|
])
|
||||||
},
|
})
|
||||||
},
|
|
||||||
}).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 () => {
|
|
||||||
const jsBinding =
|
|
||||||
"const currentTime = new Date()\ncurrentTime.setDate(currentTime.getDate()-14);\nreturn currentTime.toISOString();"
|
|
||||||
const encodedBinding = encodeJSBinding(jsBinding)
|
|
||||||
|
|
||||||
await expectQuery({
|
|
||||||
range: {
|
|
||||||
appointment: {
|
|
||||||
low: "0000-00-00T00:00:00.000Z",
|
|
||||||
high: encodedBinding,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}).toContainExactly([
|
|
||||||
{ name: "foo", appointment: "1982-01-05T00:00:00.000Z" },
|
|
||||||
{ name: "bar", appointment: "1995-05-06T00:00:00.000Z" },
|
|
||||||
])
|
|
||||||
})
|
|
||||||
|
|
||||||
it("should match a single user row by the session user id", async () => {
|
|
||||||
await expectQuery({
|
|
||||||
equal: { single_user: "{{ [user]._id }}" },
|
|
||||||
}).toContainExactly([
|
|
||||||
{
|
|
||||||
name: "single user, session user",
|
|
||||||
single_user: [{ _id: config.getUser()._id }],
|
|
||||||
},
|
|
||||||
])
|
|
||||||
})
|
|
||||||
|
|
||||||
|
!isSqs &&
|
||||||
it("should match the session user id in a multi user field", async () => {
|
it("should match the session user id in a multi user field", async () => {
|
||||||
|
const allUsers = [...globalUsers, config.getUser()].map((user: any) => {
|
||||||
|
return { _id: user._id }
|
||||||
|
})
|
||||||
|
|
||||||
await expectQuery({
|
await expectQuery({
|
||||||
contains: { multi_user: ["{{ [user]._id }}"] },
|
contains: { multi_user: ["{{ [user]._id }}"] },
|
||||||
}).toContainExactly([
|
}).toContainExactly([
|
||||||
{
|
{
|
||||||
name: "multi user with session user",
|
name: "multi user with session user",
|
||||||
multi_user: [{ _id: config.getUser()._id }],
|
multi_user: allUsers,
|
||||||
},
|
},
|
||||||
])
|
])
|
||||||
})
|
})
|
||||||
|
|
||||||
|
!isSqs &&
|
||||||
it("should not match the session user id in a multi user field", async () => {
|
it("should not match the session user id in a multi user field", async () => {
|
||||||
await expectQuery({
|
await expectQuery({
|
||||||
notContains: { multi_user: ["{{ [user]._id }}"] },
|
notContains: { multi_user: ["{{ [user]._id }}"] },
|
||||||
|
@ -360,43 +365,43 @@ describe.each([
|
||||||
])
|
])
|
||||||
})
|
})
|
||||||
|
|
||||||
it("should match the session user id and a user table row id using helpers, user binding and a static user id.", async () => {
|
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({
|
||||||
oneOf: {
|
oneOf: {
|
||||||
single_user: [
|
single_user: [
|
||||||
"{{ default [user]._id '_empty_' }}",
|
"{{ default [user]._id '_empty_' }}",
|
||||||
globalUsers[0]._id,
|
globalUsers[0]._id,
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
}).toContainExactly([
|
}).toContainExactly([
|
||||||
{
|
{
|
||||||
name: "single user, session user",
|
name: "single user, session user",
|
||||||
single_user: [{ _id: config.getUser()._id }],
|
single_user: [{ _id: config.getUser()._id }],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "single user",
|
name: "single user",
|
||||||
single_user: [{ _id: globalUsers[0]._id }],
|
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 }],
|
|
||||||
},
|
|
||||||
])
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
|
|
||||||
|
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.each([FieldType.STRING, FieldType.LONGFORM])("%s", () => {
|
describe.each([FieldType.STRING, FieldType.LONGFORM])("%s", () => {
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
await createTable({
|
await createTable({
|
||||||
|
|
|
@ -13,7 +13,7 @@ describe("run", () => {
|
||||||
afterAll(config.end)
|
afterAll(config.end)
|
||||||
|
|
||||||
it("runs successfully", async () => {
|
it("runs successfully", async () => {
|
||||||
const app = await config.createApp({ appName: "testApp" })
|
const app = await config.createApp("testApp")
|
||||||
const metadata = await dbCore.doWithDB(app.appId, async db => {
|
const metadata = await dbCore.doWithDB(app.appId, async db => {
|
||||||
const metadataDoc = await db.get(dbCore.DocumentType.APP_METADATA)
|
const metadataDoc = await db.get(dbCore.DocumentType.APP_METADATA)
|
||||||
delete metadataDoc.url
|
delete metadataDoc.url
|
||||||
|
|
|
@ -11,7 +11,7 @@ describe("run", () => {
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
await config.init()
|
await config.init()
|
||||||
app = await config.createApp({ appName: "testApp" })
|
app = await config.createApp("testApp")
|
||||||
screen = await config.createScreen()
|
screen = await config.createScreen()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
@ -22,7 +22,7 @@ describe("syncApps", () => {
|
||||||
expect(usageDoc.usageQuota.apps).toEqual(3)
|
expect(usageDoc.usageQuota.apps).toEqual(3)
|
||||||
|
|
||||||
// create an extra app to test the migration
|
// create an extra app to test the migration
|
||||||
await config.createApp({ appName: "quota-test" })
|
await config.createApp("quota-test")
|
||||||
|
|
||||||
// migrate
|
// migrate
|
||||||
await syncApps.run()
|
await syncApps.run()
|
||||||
|
|
|
@ -29,7 +29,7 @@ describe("syncRows", () => {
|
||||||
await config.createRow()
|
await config.createRow()
|
||||||
})
|
})
|
||||||
// app 2
|
// app 2
|
||||||
const app2 = await config.createApp({ appName: "second-app" })
|
const app2 = await config.createApp("second-app")
|
||||||
await context.doInAppContext(app2.appId, async () => {
|
await context.doInAppContext(app2.appId, async () => {
|
||||||
await config.createTable()
|
await config.createTable()
|
||||||
await config.createRow()
|
await config.createRow()
|
||||||
|
|
|
@ -224,14 +224,11 @@ export default class TestConfiguration {
|
||||||
// SETUP / TEARDOWN
|
// SETUP / TEARDOWN
|
||||||
|
|
||||||
// use a new id as the name to avoid name collisions
|
// use a new id as the name to avoid name collisions
|
||||||
async init(opts = {}) {
|
async init(appName = newid()) {
|
||||||
if (!this.started) {
|
if (!this.started) {
|
||||||
await startup()
|
await startup()
|
||||||
}
|
}
|
||||||
return this.newTenant({
|
return this.newTenant(appName)
|
||||||
appName: newid(),
|
|
||||||
...opts,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
end() {
|
end() {
|
||||||
|
@ -551,14 +548,14 @@ export default class TestConfiguration {
|
||||||
return this.tenantId
|
return this.tenantId
|
||||||
}
|
}
|
||||||
|
|
||||||
async newTenant(opts: {}): Promise<App> {
|
async newTenant(appName = newid()): Promise<App> {
|
||||||
this.csrfToken = generator.hash()
|
this.csrfToken = generator.hash()
|
||||||
|
|
||||||
this.tenantId = structures.tenant.id()
|
this.tenantId = structures.tenant.id()
|
||||||
this.user = await this.globalUser()
|
this.user = await this.globalUser()
|
||||||
this.userMetadataId = generateUserMetadataID(this.user._id!)
|
this.userMetadataId = generateUserMetadataID(this.user._id!)
|
||||||
|
|
||||||
return this.createApp({ appName: newid(), ...opts })
|
return this.createApp(appName)
|
||||||
}
|
}
|
||||||
|
|
||||||
doInTenant<T>(task: () => T) {
|
doInTenant<T>(task: () => T) {
|
||||||
|
@ -588,9 +585,7 @@ export default class TestConfiguration {
|
||||||
}
|
}
|
||||||
|
|
||||||
// APP
|
// APP
|
||||||
async createApp(opts: CreateAppRequest): Promise<App> {
|
async createApp(appName: string, url?: string): Promise<App> {
|
||||||
const { appName, url, snippets } = opts
|
|
||||||
|
|
||||||
this.appId = undefined
|
this.appId = undefined
|
||||||
this.app = await context.doInTenant(
|
this.app = await context.doInTenant(
|
||||||
this.tenantId!,
|
this.tenantId!,
|
||||||
|
@ -602,19 +597,6 @@ export default class TestConfiguration {
|
||||||
)
|
)
|
||||||
this.appId = this.app.appId
|
this.appId = this.app.appId
|
||||||
|
|
||||||
if (snippets) {
|
|
||||||
this.app = await this._req(
|
|
||||||
appController.update,
|
|
||||||
{
|
|
||||||
...this.app,
|
|
||||||
snippets,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
appId: this.appId,
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
return await context.doInAppContext(this.app.appId!, async () => {
|
return await context.doInAppContext(this.app.appId!, async () => {
|
||||||
// create production app
|
// create production app
|
||||||
this.prodApp = await this.publish()
|
this.prodApp = await this.publish()
|
||||||
|
|
Loading…
Reference in New Issue