Refactored out config changes and now excluding on the affected SQS/Multiuser tests

This commit is contained in:
Dean 2024-05-07 09:13:43 +01:00
parent c4807a8861
commit 04588711e2
7 changed files with 193 additions and 206 deletions

View File

@ -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()

View File

@ -179,7 +179,6 @@ 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 = []
@ -335,17 +334,23 @@ describe.each([
]) ])
}) })
!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 }}"] },

View File

@ -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

View File

@ -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()
}) })

View File

@ -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()

View File

@ -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()

View File

@ -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()