mirror of
https://github.com/Unleash/unleash.git
synced 2025-01-01 00:08:27 +01:00
This commit is contained in:
parent
e40975e1ed
commit
0a9b86f9bb
@ -0,0 +1,49 @@
|
||||
import dbInit, { type ITestDb } from '../../../test/e2e/helpers/database-init';
|
||||
import getLogger from '../../../test/fixtures/no-logger';
|
||||
import { createChangeRequestAccessReadModel } from './createChangeRequestAccessReadModel';
|
||||
import { createTestConfig } from '../../../test/config/test-config';
|
||||
import type { IChangeRequestAccessReadModel } from './change-request-access-read-model';
|
||||
|
||||
let db: ITestDb;
|
||||
|
||||
let readModel: IChangeRequestAccessReadModel;
|
||||
|
||||
beforeAll(async () => {
|
||||
db = await dbInit('change_request_access_read_model', getLogger);
|
||||
|
||||
const config = createTestConfig({
|
||||
getLogger,
|
||||
});
|
||||
|
||||
readModel = createChangeRequestAccessReadModel(db.rawDatabase, config);
|
||||
});
|
||||
|
||||
afterAll(async () => {
|
||||
await db.destroy();
|
||||
});
|
||||
|
||||
test(`Should indicate change request enabled status`, async () => {
|
||||
// no change requests
|
||||
const defaultStatus =
|
||||
await readModel.isChangeRequestsEnabledForProject('default');
|
||||
expect(defaultStatus).toBe(false);
|
||||
|
||||
// change request enabled in enabled environment
|
||||
await db.rawDatabase('change_request_settings').insert({
|
||||
project: 'default',
|
||||
environment: 'default',
|
||||
required_approvals: 1,
|
||||
});
|
||||
const enabledStatus =
|
||||
await readModel.isChangeRequestsEnabledForProject('default');
|
||||
expect(enabledStatus).toBe(true);
|
||||
|
||||
// change request enabled in disabled environment
|
||||
await db.stores.projectStore.deleteEnvironmentForProject(
|
||||
'default',
|
||||
'default',
|
||||
);
|
||||
const disabledStatus =
|
||||
await readModel.isChangeRequestsEnabledForProject('default');
|
||||
expect(disabledStatus).toBe(false);
|
||||
});
|
@ -70,14 +70,20 @@ export class ChangeRequestAccessReadModel
|
||||
public async isChangeRequestsEnabledForProject(
|
||||
project: string,
|
||||
): Promise<boolean> {
|
||||
const result = await this.db.raw(
|
||||
`SELECT EXISTS(SELECT 1
|
||||
FROM change_request_settings
|
||||
WHERE project = ?
|
||||
) AS present`,
|
||||
[project],
|
||||
);
|
||||
const { present } = result.rows[0];
|
||||
return present;
|
||||
const result = await this.db('change_request_settings')
|
||||
.join('project_environments', function () {
|
||||
return this.on(
|
||||
'change_request_settings.project',
|
||||
'project_environments.project_id',
|
||||
).andOn(
|
||||
'change_request_settings.environment',
|
||||
'project_environments.environment_name',
|
||||
);
|
||||
})
|
||||
.where('change_request_settings.project', project)
|
||||
.select('change_request_settings.project')
|
||||
.first();
|
||||
|
||||
return Boolean(result);
|
||||
}
|
||||
}
|
||||
|
@ -18,7 +18,7 @@ const FLAG_NAME = 'crarm-test-flag';
|
||||
let readModel: IChangeRequestSegmentUsageReadModel;
|
||||
|
||||
beforeAll(async () => {
|
||||
db = await dbInit('change_request_access_read_model_serial', getLogger);
|
||||
db = await dbInit('change_request_segment_usage_read_model', getLogger);
|
||||
|
||||
user = await db.stores.userStore.insert({
|
||||
username: 'cr-creator',
|
||||
|
Loading…
Reference in New Issue
Block a user