mirror of
https://github.com/logto-io/logto.git
synced 2024-12-16 20:26:19 -05:00
fix(core): fix quota guard middleware env flag (#4204)
This commit is contained in:
parent
aded22954e
commit
3d828f2e6d
5 changed files with 2 additions and 107 deletions
|
@ -1,25 +0,0 @@
|
|||
import { type SubscriptionPlan } from '#src/utils/subscription/types.js';
|
||||
|
||||
export const mockFreePlan: SubscriptionPlan = {
|
||||
id: 'free',
|
||||
name: 'Free',
|
||||
stripeProducts: [],
|
||||
quota: {
|
||||
mauLimit: 5000,
|
||||
hooksLimit: 1,
|
||||
rolesLimit: 1,
|
||||
resourcesLimit: 3,
|
||||
applicationsLimit: 3,
|
||||
omniSignInEnabled: true,
|
||||
scopesPerRoleLimit: 1,
|
||||
customDomainEnabled: false,
|
||||
machineToMachineLimit: 0,
|
||||
socialConnectorsLimit: 3,
|
||||
auditLogsRetentionDays: 3,
|
||||
scopesPerResourceLimit: 1,
|
||||
standardConnectorsLimit: 0,
|
||||
builtInEmailConnectorEnabled: true,
|
||||
},
|
||||
createdAt: new Date(),
|
||||
updatedAt: new Date(),
|
||||
};
|
|
@ -1,46 +0,0 @@
|
|||
import { createMockUtils } from '@logto/shared/esm';
|
||||
|
||||
import { mockFreePlan } from '#src/__mocks__/subscription.js';
|
||||
import { createMockCloudConnectionLibrary } from '#src/test-utils/cloud-connection.js';
|
||||
import { createMockConnectorLibrary } from '#src/test-utils/connectors.js';
|
||||
|
||||
const { jest } = import.meta;
|
||||
const { mockEsmWithActual } = createMockUtils(jest);
|
||||
|
||||
const { getTenantSubscriptionPlan } = await mockEsmWithActual(
|
||||
'#src/utils/subscription/index.js',
|
||||
() => ({
|
||||
getTenantSubscriptionPlan: jest.fn().mockResolvedValue(mockFreePlan),
|
||||
})
|
||||
);
|
||||
|
||||
const cloudConnection = createMockCloudConnectionLibrary();
|
||||
const connectors = createMockConnectorLibrary();
|
||||
|
||||
const { MockQueries } = await import('#src/test-utils/tenant.js');
|
||||
const { createQuotaLibrary } = await import('./quota.js');
|
||||
|
||||
const countNonM2mApplications = jest.fn();
|
||||
const queries = new MockQueries({
|
||||
applications: { countNonM2mApplications },
|
||||
});
|
||||
|
||||
describe('guardKey()', () => {
|
||||
afterEach(() => {
|
||||
getTenantSubscriptionPlan.mockClear();
|
||||
});
|
||||
|
||||
const { guardKey } = createQuotaLibrary(queries, cloudConnection, connectors);
|
||||
|
||||
it('should pass when limit is not exeeded', async () => {
|
||||
countNonM2mApplications.mockResolvedValueOnce({ count: 0 });
|
||||
|
||||
await expect(guardKey('applicationsLimit')).resolves.not.toThrow();
|
||||
});
|
||||
|
||||
it('should throw when limit is exeeded', async () => {
|
||||
countNonM2mApplications.mockResolvedValueOnce({ count: mockFreePlan.quota.applicationsLimit });
|
||||
|
||||
await expect(guardKey('applicationsLimit')).rejects.toThrow();
|
||||
});
|
||||
});
|
|
@ -78,8 +78,8 @@ export const createQuotaLibrary = (
|
|||
const guardKey = async (key: keyof FeatureQuota, queryKey?: string) => {
|
||||
const { isCloud, isIntegrationTest, isProduction } = EnvSet.values;
|
||||
|
||||
// Cloud only feature, skip in non-cloud production environments
|
||||
if (isProduction && !isCloud) {
|
||||
// Cloud only feature, skip in non-cloud environments
|
||||
if (!isCloud) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,21 +0,0 @@
|
|||
import { mockGetCloudConnectionData } from '#src/__mocks__/cloud-connection.js';
|
||||
import { type CloudConnectionLibrary } from '#src/libraries/cloud-connection.js';
|
||||
|
||||
const { jest } = import.meta;
|
||||
|
||||
type PublicPart<T> = { [K in keyof T]: T[K] };
|
||||
|
||||
export const createMockCloudConnectionLibrary = (): CloudConnectionLibrary => {
|
||||
class MockLibrary implements PublicPart<CloudConnectionLibrary> {
|
||||
public getCloudConnectionData = mockGetCloudConnectionData;
|
||||
|
||||
public getAccessToken = jest.fn();
|
||||
|
||||
public getClient = jest.fn();
|
||||
}
|
||||
|
||||
const library = new MockLibrary();
|
||||
|
||||
// eslint-disable-next-line no-restricted-syntax
|
||||
return library as unknown as CloudConnectionLibrary;
|
||||
};
|
|
@ -1,13 +0,0 @@
|
|||
import { type ConnectorLibrary } from '#src/libraries/connector.js';
|
||||
|
||||
const { jest } = import.meta;
|
||||
|
||||
export const createMockConnectorLibrary = (): ConnectorLibrary => {
|
||||
return {
|
||||
getCloudConnectionData: jest.fn(),
|
||||
getConnectorConfig: jest.fn(),
|
||||
getLogtoConnectors: jest.fn(),
|
||||
getLogtoConnectorsWellKnown: jest.fn(),
|
||||
getLogtoConnectorById: jest.fn(),
|
||||
};
|
||||
};
|
Loading…
Reference in a new issue