2021-08-12 15:04:37 +02:00
|
|
|
import { ValidationError } from 'joi';
|
2021-01-19 10:42:45 +01:00
|
|
|
|
2021-08-12 15:04:37 +02:00
|
|
|
import getLogger from '../../test/fixtures/no-logger';
|
|
|
|
import TagTypeService from './tag-type-service';
|
|
|
|
import {
|
2021-01-19 10:42:45 +01:00
|
|
|
ADDON_CONFIG_CREATED,
|
|
|
|
ADDON_CONFIG_DELETED,
|
2021-08-12 15:04:37 +02:00
|
|
|
ADDON_CONFIG_UPDATED,
|
|
|
|
FEATURE_CREATED,
|
|
|
|
} from '../types/events';
|
|
|
|
import createStores from '../../test/fixtures/store';
|
2021-02-04 11:02:58 +01:00
|
|
|
|
2021-08-12 15:04:37 +02:00
|
|
|
import AddonService from './addon-service';
|
|
|
|
import { IAddonDto } from '../types/stores/addon-store';
|
|
|
|
import SimpleAddon from './addon-service-test-simple-addon';
|
2022-07-12 14:13:25 +02:00
|
|
|
import { IAddonProviders } from '../addons';
|
2021-01-19 10:42:45 +01:00
|
|
|
|
2021-08-12 15:04:37 +02:00
|
|
|
const MASKED_VALUE = '*****';
|
2021-05-28 11:10:24 +02:00
|
|
|
|
2022-07-12 14:13:25 +02:00
|
|
|
let addonProvider: IAddonProviders;
|
2021-01-19 10:42:45 +01:00
|
|
|
|
|
|
|
function getSetup() {
|
2021-08-12 15:04:37 +02:00
|
|
|
const stores = createStores();
|
2021-01-19 10:42:45 +01:00
|
|
|
const tagTypeService = new TagTypeService(stores, { getLogger });
|
2021-08-12 15:04:37 +02:00
|
|
|
|
2022-07-12 14:13:25 +02:00
|
|
|
addonProvider = { simple: new SimpleAddon() };
|
2021-01-19 10:42:45 +01:00
|
|
|
return {
|
2021-04-27 09:16:44 +02:00
|
|
|
addonService: new AddonService(
|
|
|
|
stores,
|
2021-08-12 15:04:37 +02:00
|
|
|
{
|
|
|
|
getLogger,
|
|
|
|
// @ts-ignore
|
|
|
|
server: { unleashUrl: 'http://test' },
|
|
|
|
},
|
2021-04-27 09:16:44 +02:00
|
|
|
tagTypeService,
|
2021-08-12 15:04:37 +02:00
|
|
|
addonProvider,
|
2021-04-27 09:16:44 +02:00
|
|
|
),
|
2021-01-19 10:42:45 +01:00
|
|
|
stores,
|
|
|
|
tagTypeService,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2021-05-28 11:10:24 +02:00
|
|
|
test('should load addon configurations', async () => {
|
2021-01-19 10:42:45 +01:00
|
|
|
const { addonService } = getSetup();
|
|
|
|
|
|
|
|
const configs = await addonService.getAddons();
|
|
|
|
|
2021-05-28 11:10:24 +02:00
|
|
|
expect(configs.length).toBe(0);
|
2021-01-19 10:42:45 +01:00
|
|
|
});
|
|
|
|
|
2021-05-28 11:10:24 +02:00
|
|
|
test('should load provider definitions', async () => {
|
2021-01-19 10:42:45 +01:00
|
|
|
const { addonService } = getSetup();
|
|
|
|
|
2022-07-12 14:13:25 +02:00
|
|
|
const providerDefinitions = addonService.getProviderDefinitions();
|
2021-01-19 10:42:45 +01:00
|
|
|
|
2021-08-12 15:04:37 +02:00
|
|
|
const simple = providerDefinitions.find((p) => p.name === 'simple');
|
2021-01-19 10:42:45 +01:00
|
|
|
|
2021-05-28 11:10:24 +02:00
|
|
|
expect(providerDefinitions.length).toBe(1);
|
|
|
|
expect(simple.name).toBe('simple');
|
2021-01-19 10:42:45 +01:00
|
|
|
});
|
|
|
|
|
2021-05-28 11:10:24 +02:00
|
|
|
test('should not allow addon-config for unknown provider', async () => {
|
2021-01-19 10:42:45 +01:00
|
|
|
const { addonService } = getSetup();
|
|
|
|
|
2021-05-28 11:10:24 +02:00
|
|
|
await expect(async () => {
|
2021-08-12 15:04:37 +02:00
|
|
|
await addonService.createAddon(
|
|
|
|
{
|
|
|
|
provider: 'unknown',
|
|
|
|
enabled: true,
|
|
|
|
parameters: {},
|
|
|
|
events: [],
|
|
|
|
description: '',
|
|
|
|
},
|
|
|
|
'test',
|
|
|
|
);
|
2021-05-28 11:10:24 +02:00
|
|
|
}).rejects.toThrow(new TypeError('Unknown addon provider unknown'));
|
2021-01-19 10:42:45 +01:00
|
|
|
});
|
|
|
|
|
2021-05-28 11:10:24 +02:00
|
|
|
test('should trigger simple-addon eventHandler', async () => {
|
2021-01-19 10:42:45 +01:00
|
|
|
const { addonService, stores } = getSetup();
|
|
|
|
|
|
|
|
const config = {
|
|
|
|
provider: 'simple',
|
|
|
|
enabled: true,
|
|
|
|
parameters: {
|
|
|
|
url: 'http://localhost/wh',
|
|
|
|
var: 'some-value',
|
|
|
|
},
|
|
|
|
events: [FEATURE_CREATED],
|
2021-08-12 15:04:37 +02:00
|
|
|
description: '',
|
2021-01-19 10:42:45 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
await addonService.createAddon(config, 'me@mail.com');
|
|
|
|
|
|
|
|
// Feature toggle was created
|
|
|
|
await stores.eventStore.store({
|
|
|
|
type: FEATURE_CREATED,
|
|
|
|
createdBy: 'some@user.com',
|
|
|
|
data: {
|
|
|
|
name: 'some-toggle',
|
|
|
|
enabled: false,
|
|
|
|
strategies: [{ name: 'default' }],
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
const simpleProvider = addonService.addonProviders.simple;
|
2021-08-12 15:04:37 +02:00
|
|
|
// @ts-ignore
|
2021-01-19 10:42:45 +01:00
|
|
|
const events = simpleProvider.getEvents();
|
|
|
|
|
2021-05-28 11:10:24 +02:00
|
|
|
expect(events.length).toBe(1);
|
|
|
|
expect(events[0].event.type).toBe(FEATURE_CREATED);
|
|
|
|
expect(events[0].event.data.name).toBe('some-toggle');
|
2021-01-19 10:42:45 +01:00
|
|
|
});
|
|
|
|
|
2022-07-12 14:13:25 +02:00
|
|
|
test('should not trigger event handler if project of event is different from addon', async () => {
|
|
|
|
const { addonService, stores } = getSetup();
|
|
|
|
const config = {
|
|
|
|
provider: 'simple',
|
|
|
|
enabled: true,
|
|
|
|
events: [FEATURE_CREATED],
|
|
|
|
projects: ['someproject'],
|
|
|
|
description: '',
|
|
|
|
parameters: {
|
|
|
|
url: 'http://localhost:wh',
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
await addonService.createAddon(config, 'me@mail.com');
|
|
|
|
await stores.eventStore.store({
|
|
|
|
type: FEATURE_CREATED,
|
|
|
|
createdBy: 'some@user.com',
|
|
|
|
project: 'someotherproject',
|
|
|
|
data: {
|
|
|
|
name: 'some-toggle',
|
|
|
|
enabled: false,
|
|
|
|
strategies: [{ name: 'default' }],
|
|
|
|
},
|
|
|
|
});
|
|
|
|
const simpleProvider = addonService.addonProviders.simple;
|
|
|
|
// @ts-expect-error
|
|
|
|
const events = simpleProvider.getEvents();
|
|
|
|
|
|
|
|
expect(events.length).toBe(0);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('should trigger event handler if project for event is one of the desired projects for addon', async () => {
|
|
|
|
const { addonService, stores } = getSetup();
|
|
|
|
const desiredProject = 'desired';
|
|
|
|
const otherProject = 'other';
|
|
|
|
const config = {
|
|
|
|
provider: 'simple',
|
|
|
|
enabled: true,
|
|
|
|
events: [FEATURE_CREATED],
|
|
|
|
projects: [desiredProject],
|
|
|
|
description: '',
|
|
|
|
parameters: {
|
|
|
|
url: 'http://localhost:wh',
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
await addonService.createAddon(config, 'me@mail.com');
|
|
|
|
await stores.eventStore.store({
|
|
|
|
type: FEATURE_CREATED,
|
|
|
|
createdBy: 'some@user.com',
|
|
|
|
project: desiredProject,
|
|
|
|
data: {
|
|
|
|
name: 'some-toggle',
|
|
|
|
enabled: false,
|
|
|
|
strategies: [{ name: 'default' }],
|
|
|
|
},
|
|
|
|
});
|
|
|
|
await stores.eventStore.store({
|
|
|
|
type: FEATURE_CREATED,
|
|
|
|
createdBy: 'some@user.com',
|
|
|
|
project: otherProject,
|
|
|
|
data: {
|
|
|
|
name: 'other-toggle',
|
|
|
|
enabled: false,
|
|
|
|
strategies: [{ name: 'default' }],
|
|
|
|
},
|
|
|
|
});
|
|
|
|
const simpleProvider = addonService.addonProviders.simple;
|
|
|
|
// @ts-expect-error
|
|
|
|
const events = simpleProvider.getEvents();
|
|
|
|
|
|
|
|
expect(events.length).toBe(1);
|
|
|
|
expect(events[0].event.type).toBe(FEATURE_CREATED);
|
|
|
|
expect(events[0].event.data.name).toBe('some-toggle');
|
|
|
|
});
|
|
|
|
|
|
|
|
test('should trigger events for multiple projects if addon is setup to filter multiple projects', async () => {
|
|
|
|
const { addonService, stores } = getSetup();
|
|
|
|
const desiredProjects = ['desired', 'desired2'];
|
|
|
|
const otherProject = 'other';
|
|
|
|
const config = {
|
|
|
|
provider: 'simple',
|
|
|
|
enabled: true,
|
|
|
|
events: [FEATURE_CREATED],
|
|
|
|
projects: desiredProjects,
|
|
|
|
description: '',
|
|
|
|
parameters: {
|
|
|
|
url: 'http://localhost:wh',
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
await addonService.createAddon(config, 'me@mail.com');
|
|
|
|
await stores.eventStore.store({
|
|
|
|
type: FEATURE_CREATED,
|
|
|
|
createdBy: 'some@user.com',
|
|
|
|
project: desiredProjects[0],
|
|
|
|
data: {
|
|
|
|
name: 'some-toggle',
|
|
|
|
enabled: false,
|
|
|
|
strategies: [{ name: 'default' }],
|
|
|
|
},
|
|
|
|
});
|
|
|
|
await stores.eventStore.store({
|
|
|
|
type: FEATURE_CREATED,
|
|
|
|
createdBy: 'some@user.com',
|
|
|
|
project: otherProject,
|
|
|
|
data: {
|
|
|
|
name: 'other-toggle',
|
|
|
|
enabled: false,
|
|
|
|
strategies: [{ name: 'default' }],
|
|
|
|
},
|
|
|
|
});
|
|
|
|
await stores.eventStore.store({
|
|
|
|
type: FEATURE_CREATED,
|
|
|
|
createdBy: 'some@user.com',
|
|
|
|
project: desiredProjects[1],
|
|
|
|
data: {
|
|
|
|
name: 'third-toggle',
|
|
|
|
enabled: false,
|
|
|
|
strategies: [{ name: 'default' }],
|
|
|
|
},
|
|
|
|
});
|
|
|
|
const simpleProvider = addonService.addonProviders.simple;
|
|
|
|
// @ts-expect-error
|
|
|
|
const events = simpleProvider.getEvents();
|
|
|
|
|
|
|
|
expect(events.length).toBe(2);
|
|
|
|
expect(events[0].event.type).toBe(FEATURE_CREATED);
|
|
|
|
expect(events[0].event.data.name).toBe('some-toggle');
|
|
|
|
expect(events[1].event.type).toBe(FEATURE_CREATED);
|
|
|
|
expect(events[1].event.data.name).toBe('third-toggle');
|
|
|
|
});
|
|
|
|
|
|
|
|
test('should filter events on environment if addon is setup to filter for it', async () => {
|
|
|
|
const { addonService, stores } = getSetup();
|
|
|
|
const desiredEnvironment = 'desired';
|
|
|
|
const otherEnvironment = 'other';
|
|
|
|
const config = {
|
|
|
|
provider: 'simple',
|
|
|
|
enabled: true,
|
|
|
|
events: [FEATURE_CREATED],
|
|
|
|
projects: [],
|
|
|
|
environments: [desiredEnvironment],
|
|
|
|
description: '',
|
|
|
|
parameters: {
|
|
|
|
url: 'http://localhost:wh',
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
await addonService.createAddon(config, 'me@mail.com');
|
|
|
|
await stores.eventStore.store({
|
|
|
|
type: FEATURE_CREATED,
|
|
|
|
createdBy: 'some@user.com',
|
|
|
|
project: desiredEnvironment,
|
|
|
|
environment: desiredEnvironment,
|
|
|
|
data: {
|
|
|
|
name: 'some-toggle',
|
|
|
|
enabled: false,
|
|
|
|
strategies: [{ name: 'default' }],
|
|
|
|
},
|
|
|
|
});
|
|
|
|
await stores.eventStore.store({
|
|
|
|
type: FEATURE_CREATED,
|
|
|
|
createdBy: 'some@user.com',
|
|
|
|
environment: otherEnvironment,
|
|
|
|
data: {
|
|
|
|
name: 'other-toggle',
|
|
|
|
enabled: false,
|
|
|
|
strategies: [{ name: 'default' }],
|
|
|
|
},
|
|
|
|
});
|
|
|
|
const simpleProvider = addonService.addonProviders.simple;
|
|
|
|
// @ts-expect-error
|
|
|
|
const events = simpleProvider.getEvents();
|
|
|
|
|
|
|
|
expect(events.length).toBe(1);
|
|
|
|
expect(events[0].event.type).toBe(FEATURE_CREATED);
|
|
|
|
expect(events[0].event.data.name).toBe('some-toggle');
|
|
|
|
});
|
|
|
|
|
2022-07-12 15:50:22 +02:00
|
|
|
test('should support wildcard option for filtering addons', async () => {
|
|
|
|
const { addonService, stores } = getSetup();
|
|
|
|
const desiredProjects = ['desired', 'desired2'];
|
|
|
|
const otherProject = 'other';
|
|
|
|
const config = {
|
|
|
|
provider: 'simple',
|
|
|
|
enabled: true,
|
|
|
|
events: [FEATURE_CREATED],
|
|
|
|
projects: ['*'],
|
|
|
|
description: '',
|
|
|
|
parameters: {
|
|
|
|
url: 'http://localhost:wh',
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
await addonService.createAddon(config, 'me@mail.com');
|
|
|
|
await stores.eventStore.store({
|
|
|
|
type: FEATURE_CREATED,
|
|
|
|
createdBy: 'some@user.com',
|
|
|
|
project: desiredProjects[0],
|
|
|
|
data: {
|
|
|
|
name: 'some-toggle',
|
|
|
|
enabled: false,
|
|
|
|
strategies: [{ name: 'default' }],
|
|
|
|
},
|
|
|
|
});
|
|
|
|
await stores.eventStore.store({
|
|
|
|
type: FEATURE_CREATED,
|
|
|
|
createdBy: 'some@user.com',
|
|
|
|
project: otherProject,
|
|
|
|
data: {
|
|
|
|
name: 'other-toggle',
|
|
|
|
enabled: false,
|
|
|
|
strategies: [{ name: 'default' }],
|
|
|
|
},
|
|
|
|
});
|
|
|
|
await stores.eventStore.store({
|
|
|
|
type: FEATURE_CREATED,
|
|
|
|
createdBy: 'some@user.com',
|
|
|
|
project: desiredProjects[1],
|
|
|
|
data: {
|
|
|
|
name: 'third-toggle',
|
|
|
|
enabled: false,
|
|
|
|
strategies: [{ name: 'default' }],
|
|
|
|
},
|
|
|
|
});
|
|
|
|
const simpleProvider = addonService.addonProviders.simple;
|
|
|
|
// @ts-expect-error
|
|
|
|
const events = simpleProvider.getEvents();
|
|
|
|
|
|
|
|
expect(events).toHaveLength(3);
|
|
|
|
expect(events[0].event.type).toBe(FEATURE_CREATED);
|
|
|
|
expect(events[0].event.data.name).toBe('some-toggle');
|
|
|
|
expect(events[1].event.type).toBe(FEATURE_CREATED);
|
|
|
|
expect(events[1].event.data.name).toBe('other-toggle');
|
|
|
|
expect(events[2].event.type).toBe(FEATURE_CREATED);
|
|
|
|
expect(events[2].event.data.name).toBe('third-toggle');
|
|
|
|
});
|
|
|
|
|
2022-07-12 14:13:25 +02:00
|
|
|
test('Should support filtering by both project and environment', async () => {
|
|
|
|
const { addonService, stores } = getSetup();
|
|
|
|
const desiredProjects = ['desired1', 'desired2', 'desired3'];
|
|
|
|
const desiredEnvironments = ['env1', 'env2', 'env3'];
|
|
|
|
const config = {
|
|
|
|
provider: 'simple',
|
|
|
|
enabled: true,
|
|
|
|
events: [FEATURE_CREATED],
|
|
|
|
projects: desiredProjects,
|
|
|
|
environments: desiredEnvironments,
|
|
|
|
description: '',
|
|
|
|
parameters: {
|
|
|
|
url: 'http://localhost:wh',
|
|
|
|
},
|
|
|
|
};
|
|
|
|
const expectedFeatureNames = [
|
|
|
|
'desired-toggle1',
|
|
|
|
'desired-toggle2',
|
|
|
|
'desired-toggle3',
|
|
|
|
];
|
|
|
|
await addonService.createAddon(config, 'me@mail.com');
|
|
|
|
await stores.eventStore.store({
|
|
|
|
type: FEATURE_CREATED,
|
|
|
|
createdBy: 'some@user.com',
|
|
|
|
project: desiredProjects[0],
|
|
|
|
environment: desiredEnvironments[0],
|
|
|
|
data: {
|
|
|
|
name: expectedFeatureNames[0],
|
|
|
|
enabled: false,
|
|
|
|
strategies: [{ name: 'default' }],
|
|
|
|
},
|
|
|
|
});
|
|
|
|
await stores.eventStore.store({
|
|
|
|
type: FEATURE_CREATED,
|
|
|
|
createdBy: 'some@user.com',
|
|
|
|
project: desiredProjects[0],
|
|
|
|
environment: 'wrongenvironment',
|
|
|
|
data: {
|
|
|
|
name: 'other-toggle',
|
|
|
|
enabled: false,
|
|
|
|
strategies: [{ name: 'default' }],
|
|
|
|
},
|
|
|
|
});
|
|
|
|
await stores.eventStore.store({
|
|
|
|
type: FEATURE_CREATED,
|
|
|
|
createdBy: 'some@user.com',
|
|
|
|
project: desiredProjects[2],
|
|
|
|
environment: desiredEnvironments[1],
|
|
|
|
data: {
|
|
|
|
name: expectedFeatureNames[1],
|
|
|
|
enabled: false,
|
|
|
|
strategies: [{ name: 'default' }],
|
|
|
|
},
|
|
|
|
});
|
|
|
|
await stores.eventStore.store({
|
|
|
|
type: FEATURE_CREATED,
|
|
|
|
createdBy: 'some@user.com',
|
|
|
|
project: desiredProjects[2],
|
|
|
|
environment: desiredEnvironments[2],
|
|
|
|
data: {
|
|
|
|
name: expectedFeatureNames[2],
|
|
|
|
enabled: false,
|
|
|
|
strategies: [{ name: 'default' }],
|
|
|
|
},
|
|
|
|
});
|
|
|
|
await stores.eventStore.store({
|
|
|
|
type: FEATURE_CREATED,
|
|
|
|
createdBy: 'some@user.com',
|
|
|
|
project: 'wrongproject',
|
|
|
|
environment: desiredEnvironments[0],
|
|
|
|
data: {
|
|
|
|
name: 'not-expected',
|
|
|
|
enabled: false,
|
|
|
|
strategies: [{ name: 'default' }],
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
const simpleProvider = addonService.addonProviders.simple;
|
|
|
|
// @ts-expect-error
|
|
|
|
const events = simpleProvider.getEvents();
|
|
|
|
|
|
|
|
expect(events.length).toBe(3);
|
|
|
|
expect(events[0].event.type).toBe(FEATURE_CREATED);
|
|
|
|
expect(events[0].event.data.name).toBe(expectedFeatureNames[0]);
|
|
|
|
expect(events[1].event.type).toBe(FEATURE_CREATED);
|
|
|
|
expect(events[1].event.data.name).toBe(expectedFeatureNames[1]);
|
|
|
|
expect(events[2].event.type).toBe(FEATURE_CREATED);
|
|
|
|
expect(events[2].event.data.name).toBe(expectedFeatureNames[2]);
|
|
|
|
});
|
|
|
|
|
2021-05-28 11:10:24 +02:00
|
|
|
test('should create simple-addon config', async () => {
|
2021-01-19 10:42:45 +01:00
|
|
|
const { addonService } = getSetup();
|
|
|
|
|
2021-08-12 15:04:37 +02:00
|
|
|
const config: IAddonDto = {
|
2021-01-19 10:42:45 +01:00
|
|
|
provider: 'simple',
|
|
|
|
enabled: true,
|
|
|
|
parameters: {
|
|
|
|
url: 'http://localhost/wh',
|
|
|
|
var: 'some-value',
|
|
|
|
},
|
|
|
|
events: [FEATURE_CREATED],
|
2021-08-12 15:04:37 +02:00
|
|
|
description: '',
|
2021-01-19 10:42:45 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
await addonService.createAddon(config, 'me@mail.com');
|
|
|
|
const addons = await addonService.getAddons();
|
|
|
|
|
2021-05-28 11:10:24 +02:00
|
|
|
expect(addons.length).toBe(1);
|
|
|
|
expect(addons[0].provider).toBe('simple');
|
2021-01-19 10:42:45 +01:00
|
|
|
});
|
|
|
|
|
2021-05-28 11:10:24 +02:00
|
|
|
test('should create tag type for simple-addon', async () => {
|
2021-01-19 10:42:45 +01:00
|
|
|
const { addonService, tagTypeService } = getSetup();
|
|
|
|
|
2021-08-12 15:04:37 +02:00
|
|
|
const config: IAddonDto = {
|
2021-01-19 10:42:45 +01:00
|
|
|
provider: 'simple',
|
|
|
|
enabled: true,
|
|
|
|
parameters: {
|
|
|
|
url: 'http://localhost/wh',
|
|
|
|
var: 'some-value',
|
|
|
|
},
|
|
|
|
events: [FEATURE_CREATED],
|
2021-08-12 15:04:37 +02:00
|
|
|
description: '',
|
2021-01-19 10:42:45 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
await addonService.createAddon(config, 'me@mail.com');
|
|
|
|
const tagType = await tagTypeService.getTagType('me');
|
|
|
|
|
2021-05-28 11:10:24 +02:00
|
|
|
expect(tagType.name).toBe('me');
|
2021-01-19 10:42:45 +01:00
|
|
|
});
|
|
|
|
|
2021-05-28 11:10:24 +02:00
|
|
|
test('should store ADDON_CONFIG_CREATE event', async () => {
|
2021-01-19 10:42:45 +01:00
|
|
|
const { addonService, stores } = getSetup();
|
|
|
|
|
|
|
|
const config = {
|
|
|
|
provider: 'simple',
|
|
|
|
enabled: true,
|
|
|
|
parameters: {
|
|
|
|
url: 'http://localhost/wh',
|
|
|
|
var: 'some-value',
|
|
|
|
},
|
|
|
|
events: [FEATURE_CREATED],
|
2021-08-12 15:04:37 +02:00
|
|
|
description: '',
|
2021-01-19 10:42:45 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
await addonService.createAddon(config, 'me@mail.com');
|
|
|
|
|
|
|
|
const events = await stores.eventStore.getEvents();
|
|
|
|
|
2021-05-28 11:10:24 +02:00
|
|
|
expect(events.length).toBe(2); // Also tag-types where created
|
|
|
|
expect(events[1].type).toBe(ADDON_CONFIG_CREATED);
|
|
|
|
expect(events[1].data.provider).toBe('simple');
|
2021-01-19 10:42:45 +01:00
|
|
|
});
|
|
|
|
|
2021-05-28 11:10:24 +02:00
|
|
|
test('should store ADDON_CONFIG_UPDATE event', async () => {
|
2021-01-19 10:42:45 +01:00
|
|
|
const { addonService, stores } = getSetup();
|
|
|
|
|
2021-08-12 15:04:37 +02:00
|
|
|
const config: IAddonDto = {
|
|
|
|
description: '',
|
2021-01-19 10:42:45 +01:00
|
|
|
provider: 'simple',
|
|
|
|
enabled: true,
|
|
|
|
parameters: {
|
|
|
|
url: 'http://localhost/wh',
|
|
|
|
var: 'some-value',
|
|
|
|
},
|
|
|
|
events: [FEATURE_CREATED],
|
|
|
|
};
|
|
|
|
|
|
|
|
const addonConfig = await addonService.createAddon(config, 'me@mail.com');
|
|
|
|
|
|
|
|
const updated = { ...addonConfig, description: 'test' };
|
|
|
|
await addonService.updateAddon(addonConfig.id, updated, 'me@mail.com');
|
|
|
|
|
|
|
|
const events = await stores.eventStore.getEvents();
|
|
|
|
|
2021-05-28 11:10:24 +02:00
|
|
|
expect(events.length).toBe(3);
|
|
|
|
expect(events[2].type).toBe(ADDON_CONFIG_UPDATED);
|
|
|
|
expect(events[2].data.provider).toBe('simple');
|
2021-01-19 10:42:45 +01:00
|
|
|
});
|
|
|
|
|
2021-05-28 11:10:24 +02:00
|
|
|
test('should store ADDON_CONFIG_REMOVE event', async () => {
|
2021-01-19 10:42:45 +01:00
|
|
|
const { addonService, stores } = getSetup();
|
|
|
|
|
2021-08-12 15:04:37 +02:00
|
|
|
const config: IAddonDto = {
|
2021-01-19 10:42:45 +01:00
|
|
|
provider: 'simple',
|
2021-08-12 15:04:37 +02:00
|
|
|
description: '',
|
2021-01-19 10:42:45 +01:00
|
|
|
enabled: true,
|
|
|
|
parameters: {
|
|
|
|
url: 'http://localhost/wh',
|
|
|
|
var: 'some-value',
|
|
|
|
},
|
|
|
|
events: [FEATURE_CREATED],
|
|
|
|
};
|
|
|
|
|
|
|
|
const addonConfig = await addonService.createAddon(config, 'me@mail.com');
|
|
|
|
|
|
|
|
await addonService.removeAddon(addonConfig.id, 'me@mail.com');
|
|
|
|
|
|
|
|
const events = await stores.eventStore.getEvents();
|
|
|
|
|
2021-05-28 11:10:24 +02:00
|
|
|
expect(events.length).toBe(3);
|
|
|
|
expect(events[2].type).toBe(ADDON_CONFIG_DELETED);
|
|
|
|
expect(events[2].data.id).toBe(addonConfig.id);
|
2021-01-19 10:42:45 +01:00
|
|
|
});
|
2021-02-04 11:02:58 +01:00
|
|
|
|
2021-05-28 11:10:24 +02:00
|
|
|
test('should hide sensitive fields when fetching', async () => {
|
2021-02-04 11:02:58 +01:00
|
|
|
const { addonService } = getSetup();
|
|
|
|
|
2021-08-12 15:04:37 +02:00
|
|
|
const config: IAddonDto = {
|
2021-02-04 11:02:58 +01:00
|
|
|
provider: 'simple',
|
|
|
|
enabled: true,
|
2021-08-12 15:04:37 +02:00
|
|
|
description: '',
|
2021-02-04 11:02:58 +01:00
|
|
|
parameters: {
|
|
|
|
url: 'http://localhost/wh',
|
|
|
|
var: 'some-value',
|
|
|
|
sensitiveParam: 'should be hidden when fetching',
|
|
|
|
},
|
|
|
|
events: [FEATURE_CREATED],
|
|
|
|
};
|
|
|
|
|
|
|
|
const createdConfig = await addonService.createAddon(config, 'me@mail.com');
|
|
|
|
const addons = await addonService.getAddons();
|
|
|
|
const addonRetrieved = await addonService.getAddon(createdConfig.id);
|
|
|
|
|
2021-05-28 11:10:24 +02:00
|
|
|
expect(addons.length).toBe(1);
|
2021-08-12 15:04:37 +02:00
|
|
|
// @ts-ignore
|
2021-05-28 11:10:24 +02:00
|
|
|
expect(addons[0].parameters.sensitiveParam).toBe(MASKED_VALUE);
|
2021-08-12 15:04:37 +02:00
|
|
|
// @ts-ignore
|
2021-05-28 11:10:24 +02:00
|
|
|
expect(addonRetrieved.parameters.sensitiveParam).toBe(MASKED_VALUE);
|
2021-02-04 11:02:58 +01:00
|
|
|
});
|
|
|
|
|
2021-05-28 11:10:24 +02:00
|
|
|
test('should not overwrite masked values when updating', async () => {
|
2021-02-04 11:02:58 +01:00
|
|
|
const { addonService, stores } = getSetup();
|
|
|
|
|
2021-08-12 15:04:37 +02:00
|
|
|
const config: IAddonDto = {
|
2021-02-04 11:02:58 +01:00
|
|
|
provider: 'simple',
|
|
|
|
enabled: true,
|
|
|
|
parameters: {
|
|
|
|
url: 'http://localhost/wh',
|
|
|
|
var: 'some-value',
|
|
|
|
},
|
|
|
|
events: [FEATURE_CREATED],
|
2021-08-12 15:04:37 +02:00
|
|
|
description: '',
|
2021-02-04 11:02:58 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
const addonConfig = await addonService.createAddon(config, 'me@mail.com');
|
|
|
|
|
|
|
|
const updated = {
|
|
|
|
...addonConfig,
|
|
|
|
parameters: { url: MASKED_VALUE, var: 'some-new-value' },
|
|
|
|
description: 'test',
|
|
|
|
};
|
|
|
|
await addonService.updateAddon(addonConfig.id, updated, 'me@mail.com');
|
|
|
|
|
|
|
|
const updatedConfig = await stores.addonStore.get(addonConfig.id);
|
2021-08-12 15:04:37 +02:00
|
|
|
// @ts-ignore
|
2021-05-28 11:10:24 +02:00
|
|
|
expect(updatedConfig.parameters.url).toBe('http://localhost/wh');
|
2021-08-12 15:04:37 +02:00
|
|
|
// @ts-ignore
|
2021-05-28 11:10:24 +02:00
|
|
|
expect(updatedConfig.parameters.var).toBe('some-new-value');
|
2021-02-04 11:02:58 +01:00
|
|
|
});
|
2021-02-05 14:07:46 +01:00
|
|
|
|
2021-05-28 11:10:24 +02:00
|
|
|
test('should reject addon config with missing required parameter when creating', async () => {
|
2021-02-05 14:07:46 +01:00
|
|
|
const { addonService } = getSetup();
|
|
|
|
|
|
|
|
const config = {
|
|
|
|
provider: 'simple',
|
|
|
|
enabled: true,
|
|
|
|
parameters: {
|
|
|
|
var: 'some-value',
|
|
|
|
},
|
|
|
|
events: [FEATURE_CREATED],
|
2021-08-12 15:04:37 +02:00
|
|
|
description: '',
|
2021-02-05 14:07:46 +01:00
|
|
|
};
|
|
|
|
|
2021-05-28 11:10:24 +02:00
|
|
|
await expect(async () =>
|
|
|
|
addonService.createAddon(config, 'me@mail.com'),
|
|
|
|
).rejects.toThrow(ValidationError);
|
2021-02-05 14:07:46 +01:00
|
|
|
});
|
|
|
|
|
2021-05-28 11:10:24 +02:00
|
|
|
test('should reject updating addon config with missing required parameter', async () => {
|
2021-02-05 14:07:46 +01:00
|
|
|
const { addonService } = getSetup();
|
|
|
|
|
|
|
|
const addonConfig = {
|
|
|
|
provider: 'simple',
|
|
|
|
enabled: true,
|
|
|
|
parameters: {
|
|
|
|
url: 'https://some.site/api',
|
|
|
|
var: 'some-value',
|
|
|
|
},
|
|
|
|
events: [FEATURE_CREATED],
|
2021-08-12 15:04:37 +02:00
|
|
|
description: '',
|
2021-02-05 14:07:46 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
const config = await addonService.createAddon(addonConfig, 'me@mail.com');
|
|
|
|
const updated = {
|
|
|
|
...config,
|
|
|
|
parameters: { var: 'some-new-value' },
|
|
|
|
description: 'test',
|
|
|
|
};
|
2021-05-28 11:10:24 +02:00
|
|
|
await expect(async () =>
|
|
|
|
addonService.updateAddon(config.id, updated, 'me@mail.com'),
|
|
|
|
).rejects.toThrow(ValidationError);
|
2021-02-05 14:07:46 +01:00
|
|
|
});
|
2021-02-05 14:07:46 +01:00
|
|
|
|
2021-05-28 11:10:24 +02:00
|
|
|
test('Should reject addon config if a required parameter is just the empty string', async () => {
|
2021-02-05 14:07:46 +01:00
|
|
|
const { addonService } = getSetup();
|
|
|
|
|
|
|
|
const config = {
|
|
|
|
provider: 'simple',
|
|
|
|
enabled: true,
|
|
|
|
parameters: {
|
|
|
|
url: '',
|
|
|
|
var: 'some-value',
|
|
|
|
},
|
|
|
|
events: [FEATURE_CREATED],
|
2021-08-12 15:04:37 +02:00
|
|
|
description: '',
|
2021-02-05 14:07:46 +01:00
|
|
|
};
|
|
|
|
|
2021-05-28 11:10:24 +02:00
|
|
|
await expect(async () =>
|
|
|
|
addonService.createAddon(config, 'me@mail.com'),
|
|
|
|
).rejects.toThrow(ValidationError);
|
2021-02-05 14:07:46 +01:00
|
|
|
});
|