2023-02-16 08:08:51 +01:00
|
|
|
import { Db, IUnleashConfig } from 'lib/server-impl';
|
2023-02-21 10:15:57 +01:00
|
|
|
import EventStore from '../../db/event-store';
|
|
|
|
import GroupStore from '../../db/group-store';
|
|
|
|
import { AccountStore } from '../../db/account-store';
|
|
|
|
import RoleStore from '../../db/role-store';
|
|
|
|
import EnvironmentStore from '../../db/environment-store';
|
|
|
|
import { AccessStore } from '../../db/access-store';
|
|
|
|
import { AccessService, GroupService } from '../../services';
|
|
|
|
import FakeGroupStore from '../../../test/fixtures/fake-group-store';
|
|
|
|
import FakeEventStore from '../../../test/fixtures/fake-event-store';
|
|
|
|
import { FakeAccountStore } from '../../../test/fixtures/fake-account-store';
|
|
|
|
import FakeRoleStore from '../../../test/fixtures/fake-role-store';
|
|
|
|
import FakeEnvironmentStore from '../../../test/fixtures/fake-environment-store';
|
|
|
|
import FakeAccessStore from '../../../test/fixtures/fake-access-store';
|
2023-02-16 08:08:51 +01:00
|
|
|
|
|
|
|
export const createAccessService = (
|
|
|
|
db: Db,
|
|
|
|
config: IUnleashConfig,
|
|
|
|
): AccessService => {
|
2023-06-14 15:40:40 +02:00
|
|
|
const { eventBus, getLogger, flagResolver } = config;
|
2023-02-16 08:08:51 +01:00
|
|
|
const eventStore = new EventStore(db, getLogger);
|
|
|
|
const groupStore = new GroupStore(db);
|
|
|
|
const accountStore = new AccountStore(db, getLogger);
|
|
|
|
const roleStore = new RoleStore(db, eventBus, getLogger);
|
|
|
|
const environmentStore = new EnvironmentStore(db, eventBus, getLogger);
|
|
|
|
const accessStore = new AccessStore(db, eventBus, getLogger);
|
|
|
|
const groupService = new GroupService(
|
|
|
|
{ groupStore, eventStore, accountStore },
|
|
|
|
{ getLogger },
|
|
|
|
);
|
|
|
|
|
|
|
|
return new AccessService(
|
|
|
|
{ accessStore, accountStore, roleStore, environmentStore },
|
2023-06-14 15:40:40 +02:00
|
|
|
{ getLogger, flagResolver },
|
2023-02-16 08:08:51 +01:00
|
|
|
groupService,
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export const createFakeAccessService = (
|
|
|
|
config: IUnleashConfig,
|
|
|
|
): AccessService => {
|
2023-06-14 15:40:40 +02:00
|
|
|
const { getLogger, flagResolver } = config;
|
2023-02-16 08:08:51 +01:00
|
|
|
const eventStore = new FakeEventStore();
|
|
|
|
const groupStore = new FakeGroupStore();
|
|
|
|
const accountStore = new FakeAccountStore();
|
|
|
|
const roleStore = new FakeRoleStore();
|
|
|
|
const environmentStore = new FakeEnvironmentStore();
|
2023-06-22 16:42:01 +02:00
|
|
|
const accessStore = new FakeAccessStore(roleStore);
|
2023-02-16 08:08:51 +01:00
|
|
|
const groupService = new GroupService(
|
|
|
|
{ groupStore, eventStore, accountStore },
|
|
|
|
{ getLogger },
|
|
|
|
);
|
|
|
|
|
|
|
|
return new AccessService(
|
|
|
|
{ accessStore, accountStore, roleStore, environmentStore },
|
2023-06-14 15:40:40 +02:00
|
|
|
{ getLogger, flagResolver },
|
2023-02-16 08:08:51 +01:00
|
|
|
groupService,
|
|
|
|
);
|
|
|
|
};
|