mirror of
https://github.com/Unleash/unleash.git
synced 2025-01-20 00:08:02 +01:00
fix: Do not call store function in constructor
This commit is contained in:
parent
2cd5028125
commit
c52cec5df4
@ -73,27 +73,22 @@ describe('Public Signup API', () => {
|
||||
});
|
||||
|
||||
test('should create a token', async () => {
|
||||
expect.assertions(4);
|
||||
const appName = '123!23';
|
||||
|
||||
stores.clientApplicationsStore.upsert({ appName });
|
||||
stores.roleStore.create({ name: RoleName.VIEWER });
|
||||
const bodyCreate = createBody();
|
||||
|
||||
return request
|
||||
const res = await request
|
||||
.post('/api/admin/invite-link/tokens')
|
||||
.send(bodyCreate)
|
||||
.expect(201)
|
||||
.expect(async (res) => {
|
||||
const token = res.body;
|
||||
expect(token.name).toBe(bodyCreate.name);
|
||||
expect(token.secret).not.toBeNull();
|
||||
expect(token.expiresAt).toBe(
|
||||
bodyCreate.expiresAt.toISOString(),
|
||||
);
|
||||
const eventCount = await stores.eventStore.count();
|
||||
expect(eventCount).toBe(1); //PUBLIC_SIGNUP_TOKEN_CREATED
|
||||
});
|
||||
.expect(201);
|
||||
const token = res.body;
|
||||
expect(token.name).toBe(bodyCreate.name);
|
||||
expect(token.secret).not.toBeNull();
|
||||
expect(token.expiresAt).toBe(bodyCreate.expiresAt.toISOString());
|
||||
const eventCount = await stores.eventStore.count();
|
||||
expect(eventCount).toBe(1); //PUBLIC_SIGNUP_TOKEN_CREATED
|
||||
});
|
||||
|
||||
test('should get All', async () => {
|
||||
|
@ -38,6 +38,7 @@ jest.mock('./db', () => ({
|
||||
clientInstanceStore: { destroy: noop },
|
||||
clientMetricsStore: { destroy: noop, on: noop },
|
||||
eventStore,
|
||||
publicSignupTokenStore: { destroy: noop, on: noop },
|
||||
settingStore,
|
||||
};
|
||||
},
|
||||
|
@ -62,7 +62,7 @@ async function createApp(
|
||||
if (typeof config.eventHook === 'function') {
|
||||
addEventHook(config.eventHook, stores.eventStore);
|
||||
}
|
||||
metricsMonitor.startMonitoring(
|
||||
await metricsMonitor.startMonitoring(
|
||||
config,
|
||||
stores,
|
||||
serverVersion,
|
||||
|
@ -1,7 +1,6 @@
|
||||
import crypto from 'crypto';
|
||||
import { Logger } from '../logger';
|
||||
import { IUnleashConfig, IUnleashStores } from '../types';
|
||||
import { minutesToMilliseconds } from 'date-fns';
|
||||
import { IPublicSignupTokenStore } from '../types/stores/public-signup-token-store';
|
||||
import { PublicSignupTokenSchema } from '../openapi/spec/public-signup-token-schema';
|
||||
import { IRoleStore } from '../types/stores/role-store';
|
||||
@ -30,8 +29,6 @@ export class PublicSignupTokenService {
|
||||
|
||||
private timer: NodeJS.Timeout;
|
||||
|
||||
private activeTokens: PublicSignupTokenSchema[] = [];
|
||||
|
||||
constructor(
|
||||
{
|
||||
publicSignupTokenStore,
|
||||
@ -51,15 +48,6 @@ export class PublicSignupTokenService {
|
||||
this.logger = config.getLogger(
|
||||
'/services/public-signup-token-service.ts',
|
||||
);
|
||||
this.fetchActiveTokens();
|
||||
this.timer = setInterval(
|
||||
() => this.fetchActiveTokens(),
|
||||
minutesToMilliseconds(1),
|
||||
).unref();
|
||||
}
|
||||
|
||||
async fetchActiveTokens(): Promise<void> {
|
||||
this.activeTokens = await this.getAllActiveTokens();
|
||||
}
|
||||
|
||||
public async get(secret: string): Promise<PublicSignupTokenSchema> {
|
||||
@ -129,7 +117,6 @@ export class PublicSignupTokenService {
|
||||
createdBy: createdBy,
|
||||
};
|
||||
const token = await this.store.insert(newToken);
|
||||
this.activeTokens.push(token);
|
||||
|
||||
await this.eventStore.store(
|
||||
new PublicSignupTokenCreatedEvent({
|
||||
|
@ -4623,7 +4623,7 @@ If the provided project does not exist, the list of events will be empty.",
|
||||
"200": {
|
||||
"description": "This response has no body.",
|
||||
},
|
||||
"404": {
|
||||
"401": {
|
||||
"description": "This response has no body.",
|
||||
},
|
||||
},
|
||||
|
Loading…
Reference in New Issue
Block a user