Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

N21-939-assign-groups-to-course #4464

Merged
merged 20 commits into from
Oct 16, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
109 changes: 2 additions & 107 deletions test/services/courses/hooks/index.test.js
Original file line number Diff line number Diff line change
@@ -1,32 +1,21 @@
const { expect } = require('chai');
const { Configuration } = require('@hpi-schul-cloud/commons/lib');
const appPromise = require('../../../../src/app');
const testObjects = require('../../helpers/testObjects')(appPromise());
const {
restrictChangesToArchivedCourse,
addWholeClassToCourse,
} = require('../../../../src/services/user-group/hooks/courses');
const { setupNestServices, closeNestServices } = require('../../../utils/setup.nest.services');
const { restrictChangesToArchivedCourse } = require('../../../../src/services/user-group/hooks/courses');
mrikallab marked this conversation as resolved.
Show resolved Hide resolved

const oneHour = 600000;
const twoDays = 172800000;

describe('course hooks', () => {
let app;
let server;
let nestServices;
let nestGroupService;

before(async () => {
app = await appPromise();
server = app.listen(0);
nestServices = setupNestServices(app);
nestGroupService = app.service('nest-group-service');
});

after(async () => {
after(() => {
server.close();
await closeNestServices(nestServices);
});

describe('restrict changes to archived course', () => {
Expand Down Expand Up @@ -93,98 +82,4 @@ describe('course hooks', () => {
}
});
});

describe('add whole class to course', () => {
describe('when FEATURE_GROUPS_IN_COURSE_ENABLED is enabled and group are given', async () => {
const setup = async () => {
Configuration.set('FEATURE_GROUPS_IN_COURSE_ENABLED', true);
const teacher = await testObjects.createTestUser({ roles: ['teacher'] });
const student = await testObjects.createTestUser({ roles: ['student'] });
const student1 = await testObjects.createTestUser({ roles: ['student'] });
const student2 = await testObjects.createTestUser({ roles: ['student'] });
const class1 = await testObjects.createTestClass({ teacherIds: [teacher._id] });
const class2 = await testObjects.createTestClass({ teacherIds: [teacher._id], userIds: [student2._id] });
const group1 = await testObjects.createTestCourseGroup({
teacherIds: [teacher._id],
userIds: [student._id, student1._id],
});

return { teacher, student, class1, class2, group1 };
};

it('should add classmembers and groupmembers to course hook', async () => {
const { class1, class2, group1 } = await setup();

const result = addWholeClassToCourse({
app,
method: 'update',
id: '123',
data: { groupIds: [group1._id], classIds: [class1._id, class2._id] },
});

expect(result).to.not.equal(undefined);
expect(result.teacherIds).to.have.length(1);
expect(result.userIds).to.have.length(3);
});
});

describe('when FEATURE_GROUPS_IN_COURSE_ENABLED is enabled and group are not given', async () => {
const setup = async () => {
Configuration.set('FEATURE_GROUPS_IN_COURSE_ENABLED', true);
const teacher = await testObjects.createTestUser({ roles: ['teacher'] });
const student = await testObjects.createTestUser({ roles: ['student'] });
const class1 = await testObjects.createTestClass({ teacherIds: [teacher._id] });
const class2 = await testObjects.createTestClass({ teacherIds: [teacher._id] });

return { teacher, student, class1, class2 };
};

it('should add classmembers and groupmembers to course hook', async () => {
const { class1, class2 } = await setup();

const result = addWholeClassToCourse({
app,
method: 'update',
id: '123',
data: { groupIds: undefined, classIds: [class1._id, class2._id] },
});

expect(result).to.not.equal(undefined);
expect(result.teacherIds).to.have.length(1);
expect(result.userIds).to.have.length(0);
});
});

describe('when FEATURE_GROUPS_IN_COURSE_ENABLED is disabled', async () => {
const setup = async () => {
Configuration.set('FEATURE_GROUPS_IN_COURSE_ENABLED', false);
const teacher = await testObjects.createTestUser({ roles: ['teacher'] });
const student = await testObjects.createTestUser({ roles: ['student'] });
const student1 = await testObjects.createTestUser({ roles: ['student'] });
const student2 = await testObjects.createTestUser({ roles: ['student'] });
const class1 = await testObjects.createTestClass({ teacherIds: [teacher._id] });
const group1 = await testObjects.createTestCourseGroup({
teacherIds: [teacher._id],
userIds: [student._id, student1._id, student2._id],
});

return { teacher, student, class1, group1 };
};

it('should add classmembers and groupmembers to course hook', async () => {
const { class1, group1 } = await setup();

const result = addWholeClassToCourse({
app,
method: 'update',
id: '123',
data: { groupIds: [group1._id], classIds: [class1._id] },
});

expect(result.teacherIds).to.not.equal(undefined);
expect(result.teacherIds).to.have.length(1);
expect(result.userIds).to.have.length(0);
});
});
});
});
34 changes: 0 additions & 34 deletions test/services/courses/services/courses.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
const { expect } = require('chai');
const { Configuration } = require('@hpi-schul-cloud/commons/lib');

const appPromise = require('../../../../src/app');
const testObjects = require('../../helpers/testObjects')(appPromise());
Expand All @@ -9,18 +8,14 @@ describe('course service', () => {
let app;
let courseService;
let nestServices;
let server;
let nestGroupService;

before(async () => {
app = await appPromise();
nestServices = await setupNestServices(app);
courseService = app.service('courses');
nestGroupService = app.service('nest-group-service');
});

after(async () => {
await server.close();
await closeNestServices(nestServices);
});

Expand Down Expand Up @@ -91,33 +86,4 @@ describe('course service', () => {
expect(err.code).to.eq(403);
}
});

describe('Patch Course', () => {
describe('when FEATURE_GROUPS_IN_COURSE_ENABLED is enabled', async () => {
const setup = async () => {
Configuration.set('FEATURE_GROUPS_IN_COURSE_ENABLED', true);
const teacher = await testObjects.createTestUser({ roles: ['teacher'] });
const student = await testObjects.createTestUser({ roles: ['student'] });
const class1 = await testObjects.createTestClass({ teacherIds: [teacher._id] });
const group1 = await testObjects.createTestCourseGroup({ teacherIds: [teacher._id], userIds: [student._id] });

const course = await testObjects.createTestCourse({
name: 'courseNotChanged',
teacherIds: [teacher._id],
classIds: [class1._id],
groupIds: [group1._id],
});
const params = await testObjects.generateRequestParamsFromUser(teacher);

return { teacher, course, params };
};

it('should add whole classmembers and groupmembers to course', async () => {
const { course, params } = await setup();
const result = await courseService.patch(course._id, { name: 'courseChanged' }, params);
expect(result.name).to.equal('courseChanged');
expect(result.userIds).to.have.lengthOf(1);
});
});
});
});
7 changes: 1 addition & 6 deletions test/utils/setup.nest.services.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,10 @@ const { AccountService } = require('../../dist/apps/server/modules/account/servi
const {
AccountValidationService,
} = require('../../dist/apps/server/modules/account/services/account.validation.service');
const { GroupService } = require('../../dist/apps/server/modules/group/service/group.service');
const { DB_PASSWORD, DB_URL, DB_USERNAME } = require('../../dist/apps/server/config/database.config');
const { ALL_ENTITIES } = require('../../dist/apps/server/shared/domain/entity/all-entities');
const { TeamService } = require('../../dist/apps/server/modules/teams/service/team.service');
const { TeamsApiModule } = require('../../dist/apps/server/modules/teams/teams-api.module');
const { GroupApiModule } = require('../../dist/apps/server/modules/group/group-api.module');

const setupNestServices = async (app) => {
const module = await Test.createTestingModule({
Expand All @@ -33,7 +31,6 @@ const setupNestServices = async (app) => {
ConfigModule.forRoot({ ignoreEnvFile: true, ignoreEnvVars: true, isGlobal: true }),
AccountApiModule,
TeamsApiModule,
GroupApiModule,
],
}).compile();
const nestApp = await module.createNestApplication().init();
Expand All @@ -42,16 +39,14 @@ const setupNestServices = async (app) => {
const accountService = nestApp.get(AccountService);
const accountValidationService = nestApp.get(AccountValidationService);
const teamService = nestApp.get(TeamService);
const groupService = nestApp.get(GroupService);

app.services['nest-account-uc'] = accountUc;
app.services['nest-account-service'] = accountService;
app.services['nest-account-validation-service'] = accountValidationService;
app.services['nest-team-service'] = teamService;
app.services['nest-group-service'] = groupService;
app.services['nest-orm'] = orm;

return { nestApp, orm, accountUc, accountService, groupService };
return { nestApp, orm, accountUc, accountService };
};

const closeNestServices = async (nestServices) => {
Expand Down
Loading