1
0
Fork 0
mirror of synced 2024-10-02 18:16:29 +13:00

Migrate users of switchToSelfHosted to config.withEnv

This commit is contained in:
Sam Rose 2024-03-04 13:47:53 +00:00
parent 1dd4303bfb
commit 1e184605a1
No known key found for this signature in database
5 changed files with 13 additions and 23 deletions

View file

@ -13,7 +13,7 @@ describe("/api/keys", () => {
describe("fetch", () => {
it("should allow fetching", async () => {
await setup.switchToSelfHosted(async () => {
await config.withEnv({ SELF_HOSTED: "true" }, async () => {
const res = await request
.get(`/api/keys`)
.set(config.defaultHeaders())
@ -34,7 +34,7 @@ describe("/api/keys", () => {
describe("update", () => {
it("should allow updating a value", async () => {
await setup.switchToSelfHosted(async () => {
await config.withEnv({ SELF_HOSTED: "true" }, async () => {
const res = await request
.put(`/api/keys/TEST`)
.send({

View file

@ -248,4 +248,13 @@ describe("/applications", () => {
expect(devLogs.data.length).toBe(0)
})
})
describe("permissions", () => {
it("should only return apps a user has access to", async () => {
const user = await config.createUser()
const apps = await config.api.application.fetch()
expect(apps.length).toBeGreaterThan(0)
})
})
})

View file

@ -157,7 +157,7 @@ describe("/queries", () => {
})
it("should find a query in cloud", async () => {
await setup.switchToSelfHosted(async () => {
await config.withEnv({ SELF_HOSTED: "true" }, async () => {
const query = await config.createQuery()
const res = await request
.get(`/api/queries/${query._id}`)

View file

@ -882,8 +882,7 @@ describe.each([
],
tableId: table._id,
})
// the environment needs configured for this
await setup.switchToSelfHosted(async () => {
await config.withEnv({ SELF_HOSTED: "true" }, async () => {
return context.doInAppContext(config.getAppId(), async () => {
const enriched = await outputProcessing(table, [row])
expect((enriched as Row[])[0].attachment[0].url).toBe(

View file

@ -77,21 +77,3 @@ export function getConfig() {
}
return config!
}
export async function switchToSelfHosted(func: any) {
// self hosted stops any attempts to Dynamo
env._set("NODE_ENV", "production")
env._set("SELF_HOSTED", true)
let error
try {
await func()
} catch (err) {
error = err
}
env._set("NODE_ENV", "jest")
env._set("SELF_HOSTED", false)
// don't throw error until after reset
if (error) {
throw error
}
}