Skip to content

Commit

Permalink
fix feature check confitions
Browse files Browse the repository at this point in the history
  • Loading branch information
uidp committed Jan 15, 2025
1 parent 3d5ae27 commit 6275e01
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -121,55 +121,57 @@ describe('BoardContextApiHelperService', () => {
};

describe('when video conference is enabled for course', () => {
it('should return video conference feature', async () => {
const { boardNode, course } = setup();
describe('and video conference is enabled for school and config', () => {
it('should return video conference feature', async () => {
const { boardNode, course } = setup();

course.features = [CourseFeatures.VIDEOCONFERENCE];
legacySchoolService.hasFeature.mockResolvedValueOnce(false);
configService.get.mockReturnValueOnce(false);
course.features = [CourseFeatures.VIDEOCONFERENCE];
legacySchoolService.hasFeature.mockResolvedValueOnce(true);
configService.get.mockReturnValueOnce(true);

const result = await service.getFeaturesForBoardNode(boardNode.id);
const result = await service.getFeaturesForBoardNode(boardNode.id);

expect(result).toEqual([BoardFeature.VIDEOCONFERENCE]);
expect(result).toEqual([BoardFeature.VIDEOCONFERENCE]);
});
});
});

describe('when video conference is enabled for school', () => {
it('should return video conference feature', async () => {
const { boardNode, course } = setup();
describe('and video conference is disabled for school', () => {
it('should not return feature', async () => {
const { boardNode, course } = setup();

course.features = [];
legacySchoolService.hasFeature.mockResolvedValueOnce(true);
configService.get.mockReturnValueOnce(false);
course.features = [CourseFeatures.VIDEOCONFERENCE];
legacySchoolService.hasFeature.mockResolvedValueOnce(false);
configService.get.mockReturnValueOnce(true);

const result = await service.getFeaturesForBoardNode(boardNode.id);
const result = await service.getFeaturesForBoardNode(boardNode.id);

expect(result).toEqual([BoardFeature.VIDEOCONFERENCE]);
expect(result).toEqual([]);
});
});
});

describe('when video conference is enabled for config', () => {
it('should return video conference feature', async () => {
const { boardNode, course } = setup();
describe('and video conference is disabled for config', () => {
it('should not return feature', async () => {
const { boardNode, course } = setup();

course.features = [];
legacySchoolService.hasFeature.mockResolvedValueOnce(false);
configService.get.mockReturnValueOnce(true);
course.features = [CourseFeatures.VIDEOCONFERENCE];
legacySchoolService.hasFeature.mockResolvedValueOnce(true);
configService.get.mockReturnValueOnce(false);

const result = await service.getFeaturesForBoardNode(boardNode.id);
const result = await service.getFeaturesForBoardNode(boardNode.id);

expect(result).toEqual([BoardFeature.VIDEOCONFERENCE]);
expect(result).toEqual([]);
});
});
});

describe('when video conference is disabled entirely', () => {
describe('when video conference is disabled for course', () => {
it('should not return feature', async () => {
const { boardNode } = setup();

const course = courseFactory.build();
courseService.findById.mockResolvedValueOnce(course);
legacySchoolService.hasFeature.mockResolvedValueOnce(false);
configService.get.mockReturnValueOnce(false);
legacySchoolService.hasFeature.mockResolvedValueOnce(true);
configService.get.mockReturnValueOnce(true);

const result = await service.getFeaturesForBoardNode(boardNode.id);

Expand All @@ -194,29 +196,42 @@ describe('BoardContextApiHelperService', () => {
return { boardNode: column, room };
};

describe('when video conference is enabled for school', () => {
describe('when video conference is enabled for school and config', () => {
it('should return video conference feature', async () => {
const { boardNode } = setup();

legacySchoolService.hasFeature.mockResolvedValueOnce(true);
configService.get.mockReturnValueOnce(false);
configService.get.mockReturnValueOnce(true);

const result = await service.getFeaturesForBoardNode(boardNode.id);

expect(result).toEqual([BoardFeature.VIDEOCONFERENCE]);
});
});

describe('when video conference is enabled for config', () => {
it('should return video conference feature', async () => {
describe('when video conference is disabled for school', () => {
it('should not return feature', async () => {
const { boardNode } = setup();

legacySchoolService.hasFeature.mockResolvedValueOnce(false);
configService.get.mockReturnValueOnce(true);

const result = await service.getFeaturesForBoardNode(boardNode.id);

expect(result).toEqual([BoardFeature.VIDEOCONFERENCE]);
expect(result).toEqual([]);
});
});

describe('when video conference is disabled for config', () => {
it('should not return feature', async () => {
const { boardNode } = setup();

legacySchoolService.hasFeature.mockResolvedValueOnce(true);
configService.get.mockReturnValueOnce(false);

const result = await service.getFeaturesForBoardNode(boardNode.id);

expect(result).toEqual([]);
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ export class BoardContextApiHelperService {
const course = await this.courseService.findById(context.id);

if (
this.isVideoConferenceEnabledForCourse(course.features) ||
(await this.isVideoConferenceEnabledForSchool(course.school.id)) ||
this.isVideoConferenceEnabledForConfig()
this.isVideoConferenceEnabledForConfig() &&
(await this.isVideoConferenceEnabledForSchool(course.school.id)) &&
this.isVideoConferenceEnabledForCourse(course.features)
) {
features.push(BoardFeature.VIDEOCONFERENCE);
}
Expand All @@ -73,7 +73,7 @@ export class BoardContextApiHelperService {
if (context.type === BoardExternalReferenceType.Room) {
const room = await this.roomService.getSingleRoom(context.id);

if ((await this.isVideoConferenceEnabledForSchool(room.schoolId)) || this.isVideoConferenceEnabledForConfig()) {
if (this.isVideoConferenceEnabledForConfig() && (await this.isVideoConferenceEnabledForSchool(room.schoolId))) {
features.push(BoardFeature.VIDEOCONFERENCE);
}

Expand Down

0 comments on commit 6275e01

Please sign in to comment.