mirror of
https://github.com/Unleash/unleash.git
synced 2025-01-25 00:07:47 +01:00
parent
c518ddf84c
commit
635d50e1a8
@ -71,10 +71,13 @@ export default class AddonService {
|
||||
}
|
||||
|
||||
// Memoized private function
|
||||
this.fetchAddonConfigs = memoizee(async () => addonStore.getAll(), {
|
||||
promise: true,
|
||||
maxAge: ADDONS_CACHE_TIME,
|
||||
});
|
||||
this.fetchAddonConfigs = memoizee(
|
||||
async () => addonStore.getAll({ enabled: true }),
|
||||
{
|
||||
promise: true,
|
||||
maxAge: ADDONS_CACHE_TIME,
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
loadSensitiveParams(addonProviders: IAddonProviders): ISensitiveParams {
|
||||
@ -159,7 +162,6 @@ export default class AddonService {
|
||||
providerName,
|
||||
);
|
||||
} catch (err) {
|
||||
this.logger.error(err);
|
||||
if (!(err instanceof NameExistsError)) {
|
||||
this.logger.error(err);
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
export interface Store<T, K> {
|
||||
get(key: K): Promise<T>;
|
||||
getAll(): Promise<T[]>;
|
||||
getAll(query?: Object): Promise<T[]>;
|
||||
exists(key: K): Promise<boolean>;
|
||||
delete(key: K): Promise<void>;
|
||||
deleteAll(): Promise<void>;
|
||||
|
90
src/test/e2e/services/addon-service.e2e.test.ts
Normal file
90
src/test/e2e/services/addon-service.e2e.test.ts
Normal file
@ -0,0 +1,90 @@
|
||||
import dbInit from '../helpers/database-init';
|
||||
import getLogger from '../../fixtures/no-logger';
|
||||
import { createTestConfig } from '../../config/test-config';
|
||||
import AddonService from '../../../lib/services/addon-service';
|
||||
import { IUnleashStores } from '../../../lib/types';
|
||||
|
||||
import SimpleAddon from '../../../lib/services/addon-service-test-simple-addon';
|
||||
import TagTypeService from '../../../lib/services/tag-type-service';
|
||||
import { FEATURE_CREATED } from '../../../lib/types/events';
|
||||
|
||||
const addonProvider = { simple: new SimpleAddon() };
|
||||
|
||||
let db;
|
||||
let stores: IUnleashStores;
|
||||
let addonService: AddonService;
|
||||
|
||||
beforeAll(async () => {
|
||||
const config = createTestConfig({
|
||||
server: { baseUriPath: '/test' },
|
||||
});
|
||||
db = await dbInit('addon_service_serial', getLogger);
|
||||
stores = db.stores;
|
||||
const tagTypeService = new TagTypeService(stores, config);
|
||||
addonService = new AddonService(
|
||||
stores,
|
||||
config,
|
||||
tagTypeService,
|
||||
addonProvider,
|
||||
);
|
||||
});
|
||||
|
||||
afterAll(async () => {
|
||||
if (db) {
|
||||
await db.destroy();
|
||||
}
|
||||
});
|
||||
afterEach(async () => {
|
||||
const addons = await stores.addonStore.getAll();
|
||||
const deleteAll = addons.map((a) => stores.addonStore.delete(a.id));
|
||||
await Promise.all(deleteAll);
|
||||
});
|
||||
|
||||
test('should only return active addons', async () => {
|
||||
jest.useFakeTimers();
|
||||
const config = {
|
||||
provider: 'simple',
|
||||
enabled: false,
|
||||
parameters: {
|
||||
url: 'http://localhost/wh',
|
||||
var: 'some-value',
|
||||
},
|
||||
events: [FEATURE_CREATED],
|
||||
description: '',
|
||||
};
|
||||
|
||||
const config2 = {
|
||||
provider: 'simple',
|
||||
enabled: true,
|
||||
parameters: {
|
||||
url: 'http://localhost/wh',
|
||||
var: 'some-value',
|
||||
},
|
||||
events: [FEATURE_CREATED],
|
||||
description: '',
|
||||
};
|
||||
const config3 = {
|
||||
provider: 'simple',
|
||||
enabled: true,
|
||||
parameters: {
|
||||
url: 'http://localhost/wh',
|
||||
var: 'some-value',
|
||||
},
|
||||
events: [FEATURE_CREATED],
|
||||
description: '',
|
||||
};
|
||||
|
||||
await addonService.createAddon(config, 'me@mail.com');
|
||||
await addonService.createAddon(config2, 'me@mail.com');
|
||||
await addonService.createAddon(config3, 'me@mail.com');
|
||||
|
||||
jest.advanceTimersByTime(61 * 1000);
|
||||
|
||||
const activeAddons = await addonService.fetchAddonConfigs();
|
||||
const allAddons = await addonService.getAddons();
|
||||
|
||||
expect(activeAddons.length).toBe(2);
|
||||
expect(allAddons.length).toBe(3);
|
||||
|
||||
jest.useRealTimers();
|
||||
});
|
Loading…
Reference in New Issue
Block a user