Skip to content

Commit

Permalink
Merge pull request #105 from swbloom/master
Browse files Browse the repository at this point in the history
adds the creator of a classroom to that classroom
  • Loading branch information
Ryan Christiani committed Mar 16, 2017
2 parents 2dd2208 + 7da65c9 commit d00be6e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 11 deletions.
5 changes: 5 additions & 0 deletions api/course.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ course.createCourse = (req,res) => {
model.template = false;
model.created_at = +new Date();
model.test = [];

if (model.created_by !== undefined) {
model.students = [model.created_by];
}

new models.course(model).save((err,doc) => {
if(err) {
res.send({
Expand Down
26 changes: 15 additions & 11 deletions tests/course.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,10 +154,12 @@ describe('Courses', function() {
});
});

it('should create a course', (done) => {
it('should create a course with 1 user: the instructor', (done) => {
let instructor = '58c1ab27f39dfaaeae1e760b'
let courseFromTemplate = Object.assign({},template.toJSON(), {
'term': 'Summer 2015',
'description': 'Test description'
'description': 'Test description',
'created_by': instructor
});
course.createCourse({
body: courseFromTemplate
Expand All @@ -166,6 +168,7 @@ describe('Courses', function() {
mockCourse = data.course;
expect(data).to.be.an('object');
expect(data).to.have.key('course');
expect(data.course.students).to.contain(instructor);
expect(data.course.sections).to.be.an('array');
expect(data.course.students).to.be.an('array');
expect(data.course.template).to.be.eql(false);
Expand Down Expand Up @@ -208,7 +211,7 @@ describe('Courses', function() {
});
});

it('should add a user to a course', (done) => {
it('should add the first student (second user) to a course', (done) => {
course.addUser({
params: {
courseId: mockCourse._id,
Expand All @@ -219,7 +222,7 @@ describe('Courses', function() {
}, {
send(data) {
expect(data).to.be.an('object');
expect(data.course.students).to.have.length(1)
expect(data.course.students).to.have.length(2)
expect(data.course.students[0]).to.not.have.key('password');

done();
Expand All @@ -238,14 +241,14 @@ describe('Courses', function() {
}, {
send(data) {
expect(data).to.be.an('object');
expect(data.course.students).to.have.length(1)
expect(data.course.students).to.have.length(2)
expect(data.course.students[0]).to.not.have.key('password');
done();
}
})
});

it('should not create a new user for an existing user', (done) => {
it('should add a user to the course but not create a new user for an existing user', (done) => {
//Add a new user to the mock course
course.addUser({
params: {
Expand All @@ -257,11 +260,12 @@ describe('Courses', function() {
}, {
send(userData) {
expect(userData).to.be.an('object');
expect(userData.course.students).to.have.length(2);
expect(userData.course.students).to.have.length(3);
//Then make new course
course.createCourse({
body: {
title: 'Double Test'
title: 'Double Test',
created_by: '58c1ab27f39dfaaeae1e760b'
}
}, {
send(data) {
Expand All @@ -278,7 +282,7 @@ describe('Courses', function() {
}, {
send(data) {
expect(data).to.be.an('object');
expect(data.course.students).to.have.length(1);
expect(data.course.students).to.have.length(2);
// Make sure there is no new user created
models.user.find({email: 'ryan.doubleadd@hackeryou.com'}, (err,docs) => {
expect(docs).to.have.length(1);
Expand Down Expand Up @@ -307,10 +311,10 @@ describe('Courses', function() {
send(data) {
expect(data).to.be.an('object');
expect(data.course.students).to.be.an('array');
expect(data.course.students).to.have.length(1);
expect(data.course.students).to.have.length(2);
models.user.findOne({_id: student}, (err,doc) => {
expect(doc).to.be.an('object');
expect(doc.courses).to.have.length(studentModel.courses.length - 1);
expect(doc.courses).to.have.length(studentModel.courses.length > 0 ? studentModel.courses.length - 1 : 0);
done();
});
}
Expand Down

0 comments on commit d00be6e

Please sign in to comment.