org settings events + tests + stub license events
This commit is contained in:
parent
deaf0de349
commit
8a08e9322f
|
@ -130,8 +130,12 @@ exports.Events = {
|
|||
AUTOMATION_STEP_DELETED: "automation:step:deleted",
|
||||
AUTOMATION_TRIGGER_UPDATED: "automation:trigger:updated",
|
||||
|
||||
// LICENSING
|
||||
LICENSING_QUOTA_EXCEEDED: "licensing:quota:exceeded",
|
||||
// LICENSE
|
||||
LICENSE_UPGRADED: "license:upgraded",
|
||||
LICENSE_DOWNGRADED: "license:downgraded",
|
||||
LICENSE_UPDATED: "license:updated",
|
||||
LICENSE_PAIRED: "license:paired",
|
||||
LICENSE_QUOTA_EXCEEDED: "license:quota:exceeded",
|
||||
|
||||
// ACCOUNT
|
||||
ACCOUNT_CREATED: "account:created",
|
||||
|
|
|
@ -4,7 +4,7 @@ const auth = require("./auth")
|
|||
const automation = require("./automation")
|
||||
const datasource = require("./datasource")
|
||||
const email = require("./email")
|
||||
const licensing = require("./licensing")
|
||||
const license = require("./license")
|
||||
const layout = require("./layout")
|
||||
const org = require("./org")
|
||||
const query = require("./query")
|
||||
|
@ -21,7 +21,7 @@ module.exports = {
|
|||
automation,
|
||||
datasource,
|
||||
email,
|
||||
licensing,
|
||||
license,
|
||||
layout,
|
||||
org,
|
||||
query,
|
||||
|
|
|
@ -0,0 +1,30 @@
|
|||
const events = require("../events")
|
||||
const { Events } = require("../constants")
|
||||
|
||||
exports.updgraded = () => {
|
||||
const properties = {}
|
||||
events.processEvent(Events.LICENSE_UPGRADED, properties)
|
||||
}
|
||||
|
||||
exports.downgraded = () => {
|
||||
const properties = {}
|
||||
events.processEvent(Events.LICENSE_DOWNGRADED, properties)
|
||||
}
|
||||
|
||||
exports.updated = () => {
|
||||
const properties = {}
|
||||
events.processEvent(Events.LICENSE_UPDATED, properties)
|
||||
}
|
||||
|
||||
exports.paired = () => {
|
||||
const properties = {}
|
||||
events.processEvent(Events.LICENSE_PAIRED, properties)
|
||||
}
|
||||
|
||||
exports.quotaExceeded = (quotaName, value) => {
|
||||
const properties = {
|
||||
name: quotaName,
|
||||
value,
|
||||
}
|
||||
events.processEvent(Events.LICENSE_QUOTA_EXCEEDED, properties)
|
||||
}
|
|
@ -1,10 +0,0 @@
|
|||
const events = require("../events")
|
||||
const { Events } = require("../constants")
|
||||
|
||||
exports.quotaExceeded = (quotaName, value) => {
|
||||
const properties = {
|
||||
name: quotaName,
|
||||
value,
|
||||
}
|
||||
events.processEvent(Events.LICENSING_QUOTA_EXCEEDED, properties)
|
||||
}
|
|
@ -48,6 +48,14 @@ jest.mock("../../../events", () => {
|
|||
created: jest.fn(),
|
||||
deleted: jest.fn(),
|
||||
},
|
||||
org: {
|
||||
nameUpdated: jest.fn(),
|
||||
logoUpdated: jest.fn(),
|
||||
platformURLUpdated: jest.fn(),
|
||||
versionChecked: jest.fn(),
|
||||
analyticsOptOut: jest.fn(),
|
||||
npsSubmitted: jest.fn(),
|
||||
},
|
||||
}
|
||||
})
|
||||
|
||||
|
|
|
@ -29,39 +29,52 @@ const getEventFns = async (db, config) => {
|
|||
|
||||
if (!existing) {
|
||||
switch (config.type) {
|
||||
case Configs.SMTP:
|
||||
case Configs.SMTP: {
|
||||
fns.push(events.email.SMTPCreated)
|
||||
break
|
||||
case Configs.GOOGLE:
|
||||
}
|
||||
case Configs.GOOGLE: {
|
||||
fns.push(() => events.auth.SSOCreated(type))
|
||||
if (config.config.activated) {
|
||||
fns.push(() => events.auth.SSOActivated(type))
|
||||
}
|
||||
break
|
||||
case Configs.OIDC:
|
||||
}
|
||||
case Configs.OIDC: {
|
||||
fns.push(() => events.auth.SSOCreated(type))
|
||||
if (config.config.configs[0].activated) {
|
||||
fns.push(() => events.auth.SSOActivated(type))
|
||||
}
|
||||
break
|
||||
case Configs.SETTINGS:
|
||||
if (config.company) {
|
||||
}
|
||||
case Configs.SETTINGS: {
|
||||
// company
|
||||
const company = config.config.company
|
||||
if (company && company !== "Budibase") {
|
||||
fns.push(events.org.nameUpdated)
|
||||
}
|
||||
if (config.logoUrl) {
|
||||
|
||||
// logo
|
||||
const logoUrl = config.config.logoUrl
|
||||
if (logoUrl) {
|
||||
fns.push(events.org.logoUpdated)
|
||||
}
|
||||
if (config.platformUrl) {
|
||||
|
||||
// platform url
|
||||
const platformUrl = config.config.platformUrl
|
||||
if (platformUrl && platformUrl !== "http://localhost:10000") {
|
||||
fns.push(events.org.platformURLUpdated)
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
} else {
|
||||
switch (config.type) {
|
||||
case Configs.SMTP:
|
||||
case Configs.SMTP: {
|
||||
fns.push(events.email.SMTPUpdated)
|
||||
break
|
||||
case Configs.GOOGLE:
|
||||
}
|
||||
case Configs.GOOGLE: {
|
||||
fns.push(() => events.auth.SSOUpdated(type))
|
||||
if (!existing.config.activated && config.config.activated) {
|
||||
fns.push(() => events.auth.SSOActivated(type))
|
||||
|
@ -69,7 +82,8 @@ const getEventFns = async (db, config) => {
|
|||
fns.push(() => events.auth.SSODeactivated(type))
|
||||
}
|
||||
break
|
||||
case Configs.OIDC:
|
||||
}
|
||||
case Configs.OIDC: {
|
||||
fns.push(() => events.auth.SSOUpdated(type))
|
||||
if (
|
||||
!existing.config.configs[0].activated &&
|
||||
|
@ -83,19 +97,36 @@ const getEventFns = async (db, config) => {
|
|||
fns.push(() => events.auth.SSODeactivated(type))
|
||||
}
|
||||
break
|
||||
case Configs.SETTINGS:
|
||||
if (config.company && existing.company !== config.company) {
|
||||
}
|
||||
case Configs.SETTINGS: {
|
||||
// company
|
||||
const existingCompany = existing.config.company
|
||||
const company = config.config.company
|
||||
if (company && company !== "Budibase" && existingCompany !== company) {
|
||||
fns.push(events.org.nameUpdated)
|
||||
}
|
||||
if (config.logoUrl && existing.logoUrl !== config.logoUrl) {
|
||||
|
||||
// logo
|
||||
const existingLogoUrl = existing.config.logoUrl
|
||||
const logoUrl = config.config.logoUrl
|
||||
if (logoUrl && existingLogoUrl !== logoUrl) {
|
||||
fns.push(events.org.logoUpdated)
|
||||
}
|
||||
if (config.platformUrl && existing.platformUrl !== config.platformUrl) {
|
||||
|
||||
// platform url
|
||||
const existingPlatformUrl = existing.config.platformUrl
|
||||
const platformUrl = config.config.platformUrl
|
||||
if (
|
||||
platformUrl &&
|
||||
platformUrl !== "http://localhost:10000" &&
|
||||
existingPlatformUrl !== platformUrl
|
||||
) {
|
||||
fns.push(events.org.platformURLUpdated)
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return fns
|
||||
}
|
||||
|
|
|
@ -177,6 +177,56 @@ describe("configs", () => {
|
|||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe("settings", () => {
|
||||
const saveSettingsConfig = async (conf, _id, _rev) => {
|
||||
const settingsConfig = structures.configs.settings(conf)
|
||||
return saveConfig(settingsConfig, _id, _rev)
|
||||
}
|
||||
|
||||
describe("create", () => {
|
||||
it ("should create settings config with default settings", async () => {
|
||||
await config.deleteConfig(Configs.SETTINGS)
|
||||
|
||||
await saveSettingsConfig()
|
||||
|
||||
expect(events.org.nameUpdated).not.toBeCalled()
|
||||
expect(events.org.logoUpdated).not.toBeCalled()
|
||||
expect(events.org.platformURLUpdated).not.toBeCalled()
|
||||
})
|
||||
|
||||
it ("should create settings config with non-default settings", async () => {
|
||||
await config.deleteConfig(Configs.SETTINGS)
|
||||
const conf = {
|
||||
company: "acme",
|
||||
logoUrl: "http://example.com",
|
||||
platformUrl: "http://example.com"
|
||||
}
|
||||
|
||||
await saveSettingsConfig(conf)
|
||||
|
||||
expect(events.org.nameUpdated).toBeCalledTimes(1)
|
||||
expect(events.org.logoUpdated).toBeCalledTimes(1)
|
||||
expect(events.org.platformURLUpdated).toBeCalledTimes(1)
|
||||
})
|
||||
})
|
||||
|
||||
describe("update", () => {
|
||||
it ("should update settings config", async () => {
|
||||
await config.deleteConfig(Configs.SETTINGS)
|
||||
const settingsConfig = await saveSettingsConfig()
|
||||
settingsConfig.config.company = "acme"
|
||||
settingsConfig.config.logoUrl = "http://example.com"
|
||||
settingsConfig.config.platformUrl = "http://example.com"
|
||||
|
||||
await saveSettingsConfig(settingsConfig.config, settingsConfig._id, settingsConfig._rev)
|
||||
|
||||
expect(events.org.nameUpdated).toBeCalledTimes(1)
|
||||
expect(events.org.logoUpdated).toBeCalledTimes(1)
|
||||
expect(events.org.platformURLUpdated).toBeCalledTimes(1)
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
it("should return the correct checklist status based on the state of the budibase installation", async () => {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
const { Configs, LOGO_URL } = require("../../constants")
|
||||
const { Configs } = require("../../constants")
|
||||
const { utils } = require("@budibase/backend-core")
|
||||
|
||||
exports.oidc = conf => {
|
||||
|
@ -68,7 +68,7 @@ exports.settings = conf => {
|
|||
type: Configs.SETTINGS,
|
||||
config: {
|
||||
platformUrl: "http://localhost:10000",
|
||||
logoUrl: LOGO_URL,
|
||||
logoUrl: "",
|
||||
company: "Budibase",
|
||||
...conf,
|
||||
},
|
||||
|
|
Loading…
Reference in New Issue