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