Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Client instance service #5126

Merged
merged 5 commits into from
Oct 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@ async function getSetup() {
base,
clientFeatureToggleStore: stores.clientFeatureToggleStore,
request: supertest(app),
destroy: () => {
services.clientInstanceService.destroy();
},
};
}

Expand All @@ -43,26 +40,20 @@ const callGetAll = async (controller: FeatureController) => {

let base;
let request;
let destroy;

let flagResolver;

beforeEach(async () => {
const setup = await getSetup();
base = setup.base;
request = setup.request;
destroy = setup.destroy;
flagResolver = {
isEnabled: () => {
return false;
},
};
});

afterEach(() => {
destroy();
});

test('should get empty getFeatures via client', () => {
expect.assertions(1);
return request
Expand Down
9 changes: 0 additions & 9 deletions src/lib/routes/admin-api/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,25 +28,16 @@ async function getSetup() {
return {
base,
request: supertest(app),
destroy: () => {
services.clientInstanceService.destroy();
},
};
}

let request;
let base;
let destroy;

beforeEach(async () => {
const setup = await getSetup();
request = setup.request;
base = setup.base;
destroy = setup.destroy;
});

afterEach(() => {
destroy();
});

test('should get ui config', async () => {
Expand Down
9 changes: 0 additions & 9 deletions src/lib/routes/admin-api/context.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,25 +20,16 @@ async function getSetup() {
return {
base,
request: supertest(app),
destroy: () => {
services.clientInstanceService.destroy();
},
};
}

let base;
let request;
let destroy;

beforeEach(async () => {
const setup = await getSetup();
base = setup.base;
request = setup.request;
destroy = setup.destroy;
});

afterEach(async () => {
await destroy();
});

test('should get all context definitions', () => {
Expand Down
9 changes: 0 additions & 9 deletions src/lib/routes/admin-api/metrics.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,25 +19,16 @@ async function getSetup() {
stores,
perms,
config,
destroy: () => {
services.clientInstanceService.destroy();
},
};
}

let stores;
let request;
let destroy;

beforeEach(async () => {
const setup = await getSetup();
stores = setup.stores;
request = setup.request;
destroy = setup.destroy;
});

afterEach(() => {
destroy();
});

test('/api/admin/metrics/seen-toggles is deprecated', () => {
Expand Down
9 changes: 0 additions & 9 deletions src/lib/routes/admin-api/public-signup.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,11 @@ describe('Public Signup API', () => {
request: supertest(app),
stores,
perms,
destroy: () => {
services.clientInstanceService.destroy();
services.publicSignupTokenService.destroy();
},
};
}

let stores;
let request;
let destroy;

const user = {
username: 'some-username',
Expand All @@ -55,12 +50,8 @@ describe('Public Signup API', () => {
const setup = await getSetup();
stores = setup.stores;
request = setup.request;
destroy = setup.destroy;
});

afterEach(() => {
destroy();
});
const expireAt = (addDays: number = 7): Date => {
const now = new Date();
now.setDate(now.getDate() + addDays);
Expand Down
10 changes: 0 additions & 10 deletions src/lib/routes/admin-api/strategy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import permissions from '../../../test/fixtures/permissions';
import getApp from '../../app';
import { createServices } from '../../services';

let destroy;

async function getSetup() {
const randomBase = `/random${Math.round(Math.random() * 1000)}`;
const perms = permissions();
Expand All @@ -18,10 +16,6 @@ async function getSetup() {
const services = createServices(stores, config);
const app = await getApp(config, stores, services);

destroy = () => {
services.clientInstanceService.destroy();
};

return {
base: randomBase,
strategyStore: stores.strategyStore,
Expand All @@ -30,10 +24,6 @@ async function getSetup() {
};
}

afterEach(() => {
destroy();
});

test('add version numbers for /strategies', async () => {
const { request, base } = await getSetup();
return request
Expand Down
8 changes: 0 additions & 8 deletions src/lib/routes/admin-api/tag.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,26 +21,18 @@ async function getSetup() {
perms,
tagStore: stores.tagStore,
request: supertest(app),
destroy: () => {
services.clientInstanceService.destroy();
},
};
}

let base;
let tagStore;
let request;
let destroy;

beforeEach(async () => {
const setup = await getSetup();
base = setup.base;
tagStore = setup.tagStore;
request = setup.request;
destroy = setup.destroy;
});
afterEach(() => {
destroy();
});

test('should get empty getTags via admin', () => {
Expand Down
1 change: 0 additions & 1 deletion src/lib/routes/backstage.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,4 @@ test('should enable prometheus', async () => {
.get('/internal-backstage/prometheus')
.expect('Content-Type', /text/)
.expect(200);
services.clientInstanceService.destroy();
});
13 changes: 7 additions & 6 deletions src/lib/routes/client-api/metrics.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,7 @@ async function getSetup(opts?: IUnleashOptions) {
request: supertest(app),
stores: db.stores,
services,
destroy: async () => {
services.clientInstanceService.destroy();
await db.destroy();
},
destroy: db.destroy,
};
}

Expand All @@ -31,18 +28,22 @@ let stores: IUnleashStores;
let services: IUnleashServices;
let destroy;

beforeEach(async () => {
beforeAll(async () => {
const setup = await getSetup();
request = setup.request;
stores = setup.stores;
destroy = setup.destroy;
services = setup.services;
});

afterEach(() => {
afterAll(() => {
destroy();
});

afterEach(async () => {
await stores.featureToggleStore.deleteAll();
});

test('should validate client metrics', () => {
return request
.post('/api/client/metrics')
Expand Down
6 changes: 0 additions & 6 deletions src/lib/routes/client-api/register.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,14 @@ async function getSetup() {
return {
request: supertest(app),
stores,
destroy: () => {
services.clientInstanceService.destroy();
},
};
}
let request;
let destroy;
beforeEach(async () => {
const setup = await getSetup();
request = setup.request;
destroy = setup.destroy;
});
afterEach(() => {
destroy();
getLogger.setMuteError(false);
});

Expand Down
6 changes: 0 additions & 6 deletions src/lib/routes/health-check.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,15 @@ async function getSetup() {
return {
request: supertest(app),
stores,
destroy: () => {
services.clientInstanceService.destroy();
},
};
}
let request;
let destroy;
beforeEach(async () => {
const setup = await getSetup();
request = setup.request;
destroy = setup.destroy;
});

afterEach(() => {
destroy();
getLogger.setMuteError(false);
});

Expand Down
9 changes: 0 additions & 9 deletions src/lib/routes/public-invite.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,11 @@ describe('Public Signup API', () => {
request: supertest(app),
stores,
perms,
destroy: () => {
services.clientInstanceService.destroy();
services.publicSignupTokenService.destroy();
},
};
}

let stores;
let request;
let destroy;

const user = {
username: 'some-username',
Expand All @@ -61,12 +56,8 @@ describe('Public Signup API', () => {
const setup = await getSetup();
stores = setup.stores;
request = setup.request;
destroy = setup.destroy;
});

afterEach(() => {
destroy();
});
const expireAt = (addDays: number = 7): Date => {
const now = new Date();
now.setDate(now.getDate() + addDays);
Expand Down
Loading