1
0
Fork 0
mirror of synced 2024-10-01 09:38:55 +13:00

/api/global/license/offline/identifier API

This commit is contained in:
Rory Powell 2023-07-08 13:07:10 +01:00
parent 9e1e869949
commit 90e869dc04
7 changed files with 44 additions and 3 deletions

View file

@ -17,3 +17,9 @@ export interface ActivateOfflineLicenseRequest {
export interface GetOfflineLicenseResponse {
offlineLicenseToken: string
}
// IDENTIFIER
export interface GetOfflineIdentifierResponse {
identifierBase64: string
}

View file

@ -1,5 +1,15 @@
import { PurchasedPlan, Quotas, Feature, Billing } from "."
export interface OfflineIdentifier {
installId: string,
tenantId: string
}
// export interface OfflineLicense extends License {
// identifier?: OfflineIdentifier
// identifierBase64: string
// }
export interface License {
features: Feature[]
quotas: Quotas

View file

@ -11,6 +11,7 @@ const pro = {
activateOfflineLicense: jest.fn(),
getOfflineLicenseToken: jest.fn(),
deleteOfflineLicenseToken: jest.fn(),
getIdentifierBase64: jest.fn()
},
cache: {
...actual.licensing.cache,

View file

@ -3,6 +3,7 @@ import {
ActivateLicenseKeyRequest,
ActivateOfflineLicenseRequest,
GetLicenseKeyResponse,
GetOfflineIdentifierResponse,
GetOfflineLicenseResponse,
UserCtx,
} from "@budibase/types"
@ -53,6 +54,12 @@ export async function deleteOfflineLicense(ctx: UserCtx<void, void>) {
ctx.status = 204
}
export async function getOfflineLicenseIdentifier(ctx: UserCtx<void, GetOfflineIdentifierResponse>) {
const identifierBase64 = await licensing.offline.getIdentifierBase64()
ctx.body = { identifierBase64 }
ctx.status = 200
}
// LICENSES
export const refresh = async (ctx: any) => {

View file

@ -24,5 +24,6 @@ router
.post("/api/global/license/offline", activateOfflineLicenseValidator, controller.activateOfflineLicense)
.get("/api/global/license/offline", controller.getOfflineLicense)
.delete("/api/global/license/offline", controller.deleteOfflineLicense)
.get("/api/global/license/offline/identifier", controller.getOfflineLicenseIdentifier)
export default router

View file

@ -26,7 +26,7 @@ describe("/api/global/license", () => {
})
describe("GET /api/global/license/usage", () => {
it("returns 200", async () => {
it("returns 200 + usage", async () => {
const usage = structures.quotas.usage()
quotas.getQuotaUsage.mockResolvedValue(usage)
const res = await config.api.license.getUsage()
@ -79,7 +79,7 @@ describe("/api/global/license", () => {
const res = await config.api.license.getOfflineLicense()
expect(res.status).toBe(404)
})
it("returns 200", async () => {
it("returns 200 + offline license token", async () => {
licensing.offline.getOfflineLicenseToken.mockResolvedValue("offlineLicenseToken")
const res = await config.api.license.getOfflineLicense()
expect(res.status).toBe(200)
@ -90,10 +90,21 @@ describe("/api/global/license", () => {
})
describe("DELETE /api/global/license/offline", () => {
it("deletes offline license", async () => {
it("returns 204", async () => {
const res = await config.api.license.deleteOfflineLicense()
expect(res.status).toBe(204)
expect(licensing.offline.deleteOfflineLicenseToken).toBeCalledTimes(1)
})
})
describe("GET /api/global/license/offline/identifier", () => {
it("returns 200 + identifier base64", async () => {
licensing.offline.getIdentifierBase64.mockResolvedValue("base64")
const res = await config.api.license.getOfflineLicenseIdentifier()
expect(res.status).toBe(200)
expect(res.body).toEqual({
identifierBase64: "base64"
})
})
})
})

View file

@ -51,4 +51,9 @@ export class LicenseAPI extends TestAPI {
.delete("/api/global/license/offline")
.set(this.config.defaultHeaders())
}
getOfflineLicenseIdentifier = async () => {
return this.request
.get("/api/global/license/offline/identifier")
.set(this.config.defaultHeaders())
}
}