api / license.spec.ts updates
This commit is contained in:
parent
19d3e12177
commit
7831579e98
|
@ -264,7 +264,7 @@ const getEventTenantId = async (tenantId: string): Promise<string> => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const getUniqueTenantId = async (tenantId: string): Promise<string> => {
|
export const getUniqueTenantId = async (tenantId: string): Promise<string> => {
|
||||||
// make sure this tenantId always matches the tenantId in context
|
// make sure this tenantId always matches the tenantId in context
|
||||||
return context.doInTenant(tenantId, () => {
|
return context.doInTenant(tenantId, () => {
|
||||||
return withCache(CacheKey.UNIQUE_TENANT_ID, TTL.ONE_DAY, async () => {
|
return withCache(CacheKey.UNIQUE_TENANT_ID, TTL.ONE_DAY, async () => {
|
||||||
|
|
|
@ -64,4 +64,5 @@ export const refresh = async (ctx: any) => {
|
||||||
|
|
||||||
export const getQuotaUsage = async (ctx: any) => {
|
export const getQuotaUsage = async (ctx: any) => {
|
||||||
ctx.body = await quotas.getQuotaUsage()
|
ctx.body = await quotas.getQuotaUsage()
|
||||||
|
ctx.status = 200
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,6 @@
|
||||||
import { TestConfiguration } from "../../../../tests"
|
import { TestConfiguration, mocks, structures } from "../../../../tests"
|
||||||
|
const licensing = mocks.pro.licensing
|
||||||
|
const quotas = mocks.pro.quotas
|
||||||
|
|
||||||
describe("/api/global/license", () => {
|
describe("/api/global/license", () => {
|
||||||
const config = new TestConfiguration()
|
const config = new TestConfiguration()
|
||||||
|
@ -12,15 +14,86 @@ describe("/api/global/license", () => {
|
||||||
})
|
})
|
||||||
|
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
jest.clearAllMocks()
|
jest.resetAllMocks()
|
||||||
})
|
})
|
||||||
|
|
||||||
describe("POST /api/global/license/activate", () => {
|
describe("POST /api/global/license/refresh", () => {
|
||||||
it("activates license", () => {})
|
it("returns 200", async () => {
|
||||||
|
const res = await config.api.license.refresh()
|
||||||
|
expect(res.status).toBe(200)
|
||||||
|
expect(licensing.cache.refresh).toBeCalledTimes(1)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe("POST /api/global/license/refresh", () => {})
|
describe("GET /api/global/license/usage", () => {
|
||||||
|
it("returns 200", async () => {
|
||||||
|
const usage = structures.quotas.usage()
|
||||||
|
quotas.getQuotaUsage.mockResolvedValue(usage)
|
||||||
|
const res = await config.api.license.getUsage()
|
||||||
|
expect(res.status).toBe(200)
|
||||||
|
expect(res.body).toEqual(usage)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
describe("POST /api/global/license/key", () => {
|
||||||
|
it("returns 200", async () => {
|
||||||
|
const res = await config.api.license.activateLicenseKey({ licenseKey: "licenseKey" })
|
||||||
|
expect(res.status).toBe(200)
|
||||||
|
expect(licensing.keys.activateLicenseKey).toBeCalledWith("licenseKey")
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
describe("GET /api/global/license/usage", () => {})
|
describe("GET /api/global/license/key", () => {
|
||||||
|
it("returns 404 when not found", async () => {
|
||||||
|
const res = await config.api.license.getLicenseKey()
|
||||||
|
expect(res.status).toBe(404)
|
||||||
|
})
|
||||||
|
it("returns 200 + license key", async () => {
|
||||||
|
licensing.keys.getLicenseKey.mockResolvedValue("licenseKey")
|
||||||
|
const res = await config.api.license.getLicenseKey()
|
||||||
|
expect(res.status).toBe(200)
|
||||||
|
expect(res.body).toEqual({
|
||||||
|
licenseKey: "*"
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
describe("DELETE /api/global/license/key", () => {
|
||||||
|
it("returns 204", async () => {
|
||||||
|
const res = await config.api.license.deleteLicenseKey()
|
||||||
|
expect(licensing.keys.deleteLicenseKey).toBeCalledTimes(1)
|
||||||
|
expect(res.status).toBe(204)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
describe("POST /api/global/license/offline", () => {
|
||||||
|
it("activates offline license", async () => {
|
||||||
|
const res = await config.api.license.activateOfflineLicense({ offlineLicenseToken: "offlineLicenseToken"})
|
||||||
|
expect(licensing.offline.activateOfflineLicense).toBeCalledWith("offlineLicenseToken")
|
||||||
|
expect(res.status).toBe(200)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
describe("GET /api/global/license/offline", () => {
|
||||||
|
it("returns 404 when not found", async () => {
|
||||||
|
const res = await config.api.license.getOfflineLicense()
|
||||||
|
expect(res.status).toBe(404)
|
||||||
|
})
|
||||||
|
it("returns 200", async () => {
|
||||||
|
licensing.offline.getOfflineLicenseToken.mockResolvedValue("offlineLicenseToken")
|
||||||
|
const res = await config.api.license.getOfflineLicense()
|
||||||
|
expect(res.status).toBe(200)
|
||||||
|
expect(res.body).toEqual({
|
||||||
|
offlineLicenseToken: "*"
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
describe("DELETE /api/global/license/offline", () => {
|
||||||
|
it("deletes offline license", async () => {
|
||||||
|
const res = await config.api.license.deleteOfflineLicense()
|
||||||
|
expect(res.status).toBe(204)
|
||||||
|
expect(licensing.offline.deleteOfflineLicenseToken).toBeCalledTimes(1)
|
||||||
|
})
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
|
@ -1,17 +1,54 @@
|
||||||
import TestConfiguration from "../TestConfiguration"
|
import TestConfiguration from "../TestConfiguration"
|
||||||
import { TestAPI } from "./base"
|
import { TestAPI } from "./base"
|
||||||
|
import { ActivateLicenseKeyRequest, ActivateOfflineLicenseRequest } from "@budibase/types"
|
||||||
|
|
||||||
export class LicenseAPI extends TestAPI {
|
export class LicenseAPI extends TestAPI {
|
||||||
constructor(config: TestConfiguration) {
|
constructor(config: TestConfiguration) {
|
||||||
super(config)
|
super(config)
|
||||||
}
|
}
|
||||||
|
|
||||||
activate = async (licenseKey: string) => {
|
refresh = async () => {
|
||||||
return this.request
|
return this.request
|
||||||
.post("/api/global/license/activate")
|
.post("/api/global/license/refresh")
|
||||||
.send({ licenseKey: licenseKey })
|
.set(this.config.defaultHeaders())
|
||||||
|
}
|
||||||
|
getUsage = async () => {
|
||||||
|
return this.request
|
||||||
|
.get("/api/global/license/usage")
|
||||||
.set(this.config.defaultHeaders())
|
.set(this.config.defaultHeaders())
|
||||||
.expect("Content-Type", /json/)
|
.expect("Content-Type", /json/)
|
||||||
.expect(200)
|
.expect(200)
|
||||||
}
|
}
|
||||||
|
activateLicenseKey = async (body: ActivateLicenseKeyRequest) => {
|
||||||
|
return this.request
|
||||||
|
.post("/api/global/license/key")
|
||||||
|
.send(body)
|
||||||
|
.set(this.config.defaultHeaders())
|
||||||
|
}
|
||||||
|
getLicenseKey = async () => {
|
||||||
|
return this.request
|
||||||
|
.get("/api/global/license/key")
|
||||||
|
.set(this.config.defaultHeaders())
|
||||||
|
}
|
||||||
|
deleteLicenseKey = async () => {
|
||||||
|
return this.request
|
||||||
|
.delete("/api/global/license/key")
|
||||||
|
.set(this.config.defaultHeaders())
|
||||||
|
}
|
||||||
|
activateOfflineLicense = async (body: ActivateOfflineLicenseRequest) => {
|
||||||
|
return this.request
|
||||||
|
.post("/api/global/license/offline")
|
||||||
|
.send(body)
|
||||||
|
.set(this.config.defaultHeaders())
|
||||||
|
}
|
||||||
|
getOfflineLicense = async () => {
|
||||||
|
return this.request
|
||||||
|
.get("/api/global/license/offline")
|
||||||
|
.set(this.config.defaultHeaders())
|
||||||
|
}
|
||||||
|
deleteOfflineLicense = async () => {
|
||||||
|
return this.request
|
||||||
|
.delete("/api/global/license/offline")
|
||||||
|
.set(this.config.defaultHeaders())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue