1
0
Fork 0
mirror of synced 2024-06-01 10:09:48 +12:00
budibase/qa-core/src/account-api/tests/licensing/offline.spec.ts

80 lines
2.5 KiB
TypeScript
Raw Normal View History

2023-07-15 11:12:18 +12:00
import TestConfiguration from "../../config/TestConfiguration"
import * as fixures from "../../fixtures"
import { Hosting, Feature } from "@budibase/types"
describe("offline", () => {
const config = new TestConfiguration()
beforeAll(async () => {
await config.beforeAll()
})
afterAll(async () => {
await config.afterAll()
})
// TODO: Currently requires a self host install + account portal
2023-07-25 22:12:36 +12:00
// Ignored until we set this up
2024-03-19 22:46:10 +13:00
it.skip("creates, activates and deletes offline license", async () => {
2023-07-15 11:12:18 +12:00
// installation: Delete any token
await config.internalApi.license.deleteOfflineLicenseToken()
// installation: Assert token not found
2023-07-25 22:28:14 +12:00
let [getTokenRes] = await config.internalApi.license.getOfflineLicenseToken(
{ status: 404 }
)
2023-07-15 11:12:18 +12:00
// installation: Retrieve Identifier
2023-07-25 22:28:14 +12:00
const [getIdentifierRes, identifier] =
await config.internalApi.license.getOfflineIdentifier()
2023-07-15 11:12:18 +12:00
// account-portal: Create self-host account
2023-07-25 22:28:14 +12:00
const createAccountRequest = fixures.accounts.generateAccount({
hosting: Hosting.SELF,
})
const [createAccountRes, account] =
await config.accountsApi.accounts.create(createAccountRequest)
2023-07-15 11:12:18 +12:00
const accountId = account.accountId!
const tenantId = account.tenantId!
// account-portal: Enable feature on license
await config.accountsApi.licenses.updateLicense(accountId, {
overrides: {
2023-07-25 22:28:14 +12:00
features: [Feature.OFFLINE],
},
2023-07-15 11:12:18 +12:00
})
// account-portal: Create offline token
const expireAt = new Date()
expireAt.setDate(new Date().getDate() + 1)
await config.accountsApi.licenses.createOfflineLicense(
accountId,
tenantId,
{
2023-07-25 22:28:14 +12:00
expireAt: expireAt.toISOString(),
installationIdentifierBase64: identifier.identifierBase64,
}
)
2023-07-15 11:12:18 +12:00
// account-portal: Retrieve offline token
2023-07-25 22:28:14 +12:00
const [getLicenseRes, offlineLicense] =
await config.accountsApi.licenses.getOfflineLicense(accountId, tenantId)
2023-07-15 11:12:18 +12:00
// installation: Activate offline token
await config.internalApi.license.activateOfflineLicenseToken({
2023-07-25 22:28:14 +12:00
offlineLicenseToken: offlineLicense.offlineLicenseToken,
2023-07-15 11:12:18 +12:00
})
// installation: Assert token found
await config.internalApi.license.getOfflineLicenseToken()
// TODO: Assert on license for current user
// installation: Remove the token
await config.internalApi.license.deleteOfflineLicenseToken()
// installation: Assert token not found
await config.internalApi.license.getOfflineLicenseToken({ status: 404 })
})
2023-07-25 22:28:14 +12:00
})