Skip to content

Commit

Permalink
Move logic from system to school service
Browse files Browse the repository at this point in the history
  • Loading branch information
dyedwiper committed Jan 25, 2024
1 parent fc92ee8 commit 3dfd70a
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -388,14 +388,17 @@ describe('SchoolService', () => {
describe('getSchoolsForLdapLogin', () => {
describe('when some schools exist that have ldap login systems', () => {
const setup = () => {
const ldapLoginSystem = systemFactory.build();
const ldapLoginSystem = systemFactory.build({ type: 'ldap', ldapConfig: { active: true } });
const otherSystem = systemFactory.build({ type: 'oauth2' });
const schoolWithLdapLoginSystem = schoolFactory.build({ systemIds: [ldapLoginSystem.id] });
const schoolWithoutLdapLoginSystem = schoolFactory.build();
const schoolWithOtherSystem = schoolFactory.build({ systemIds: [otherSystem.id] });
const schoolWithoutSystem = schoolFactory.build();

systemService.findAllForLdapLogin.mockResolvedValueOnce([ldapLoginSystem]);
systemService.findAll.mockResolvedValueOnce([ldapLoginSystem, otherSystem]);
schoolRepo.getAllThatHaveSystems.mockResolvedValueOnce([
schoolWithLdapLoginSystem,
schoolWithoutLdapLoginSystem,
schoolWithOtherSystem,
schoolWithoutSystem,
]);

const expected = new SchoolForLdapLogin({
Expand All @@ -422,13 +425,13 @@ describe('SchoolService', () => {
});
});

describe('when a school exists that has several systems', () => {
describe('when a school has several systems', () => {
const setup = () => {
const ldapLoginSystem = systemFactory.build();
const otherSystem = systemFactory.build();
const ldapLoginSystem = systemFactory.build({ type: 'ldap', ldapConfig: { active: true } });
const otherSystem = systemFactory.build({ type: 'oauth2' });
const school = schoolFactory.build({ systemIds: [ldapLoginSystem.id, otherSystem.id] });

systemService.findAllForLdapLogin.mockResolvedValueOnce([ldapLoginSystem]);
systemService.findAll.mockResolvedValueOnce([ldapLoginSystem, otherSystem]);
schoolRepo.getAllThatHaveSystems.mockResolvedValueOnce([school]);

const expected = new SchoolForLdapLogin({
Expand All @@ -446,7 +449,7 @@ describe('SchoolService', () => {
return { expected };
};

it('should return the school with only the LDAP login system', async () => {
it('should return the school with only the LDAP login systems', async () => {
const { expected } = setup();

const result = await service.getSchoolsForLdapLogin();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,9 @@ export class SchoolService {

public async getSchoolsForLdapLogin(): Promise<SchoolForLdapLogin[]> {
const schools = await this.schoolRepo.getAllThatHaveSystems();
const ldapLoginSystems = await this.systemService.findAllForLdapLogin();
const systems = await this.systemService.findAll();

const ldapLoginSystems = systems.filter((system) => system.isEligibleForLdapLogin());
const schoolsWithLdapLoginSystems = schools.filter((school) => this.hasLdapLoginSystem(school, ldapLoginSystems));

const schoolsForLdapLogin = schoolsWithLdapLoginSystems.map((school) =>
Expand Down
6 changes: 2 additions & 4 deletions apps/server/src/modules/system/service/system.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,10 @@ export class SystemService {
return system;
}

public async findAllForLdapLogin(): Promise<System[]> {
public async findAll(): Promise<System[]> {
const systems = await this.systemRepo.findAll();

const systemsForLdapLogin = systems.filter((system) => system.isEligibleForLdapLogin());

return systemsForLdapLogin;
return systems;
}

public async delete(domainObject: System): Promise<boolean> {
Expand Down

0 comments on commit 3dfd70a

Please sign in to comment.