Skip to content

Commit f0cc713

Browse files
committed
Updated user data for testing
1 parent bbf0d77 commit f0cc713

File tree

8 files changed

+233
-72
lines changed

8 files changed

+233
-72
lines changed
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import { Injectable } from '@angular/core';
2+
import { CanActivate, Router, ActivatedRouteSnapshot, RouterStateSnapshot } from '@angular/router';
3+
4+
import { InjectUser } from 'angular2-meteor-accounts-ui';
5+
import { Roles } from '../../../../collections/users.ts';
6+
7+
import { Observable } from 'rxjs/Observable';
8+
import 'rxjs/add/observable/fromPromise';
9+
10+
declare var Collections : any;
11+
12+
/**
13+
Guards a route by ensuring that a course record has been created for the user.
14+
**/
15+
16+
@InjectUser("user")
17+
@Injectable()
18+
export class CourseGuardRecord implements CanActivate{
19+
user: Meteor.User;
20+
21+
constructor(private router: Router) {}
22+
23+
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot){
24+
var slf = this;
25+
26+
// Get Params
27+
const course_id : string = (<any>state).parent(route).params.courseid;
28+
const lab_id : string = (<any>route).params.labid;
29+
30+
var obs : Observable<boolean> = Observable.fromPromise(new Promise<boolean> (function(resolve, reject){
31+
Meteor.startup(function(){
32+
33+
console.log(Meteor.user());
34+
35+
Meteor.subscribe('course-records', () => {
36+
// Enroll Authenticated Users
37+
if(!!Meteor.user()){
38+
var course_record = Collections.course_records.findOne({user_id: slf.user._id, course_id: course_id});
39+
if (typeof course_record !== "undefined" && course_record !== null){
40+
console.log("Course Record was created");
41+
resolve(true);
42+
}
43+
else{
44+
console.log("Course Record not Created");
45+
Meteor.call('createUserCourseRecord');
46+
resolve(true);
47+
}
48+
}
49+
else{
50+
slf.router.navigate(['/login']);
51+
return false;
52+
}
53+
});
54+
55+
});
56+
}));
57+
58+
return obs;
59+
}
60+
}

server/imports/course/search.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
var async = require ('async');
2+
3+
declare var Collections : any;
4+
25
/**
36
Searches Courses based on search terms
47
**/

tests/example_data/courses/courses.js

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
/**
2+
Example Courses Database for the TuxLab Project
3+
**/
4+
5+
module.exports = [
6+
{
7+
course_number: '15-131',
8+
course_name: 'Great Practical Ideas for Computer Scientists',
9+
course_description: {
10+
content: `
11+
Throughout your education as a Computer Scientist at Carnegie Mellon,
12+
you will take courses on programming, theoretical ideas, logic, systems,
13+
etc. As you progress, you will be expected to pick up the so-called
14+
“tools of the trade.” This course is intended to help you learn what you
15+
need to know in a friendly, low-stress, high-support way. We will discuss
16+
UNIX, LaTeX, debugging and many other essential tools.
17+
`,
18+
syllabus: 'The syllabus is here.'
19+
},
20+
instructor_ids: [],
21+
hidden: false,
22+
disabled: false,
23+
featured: true,
24+
labs: []
25+
},
26+
{
27+
course_number: '15-112',
28+
course_name: 'Fundamentals of Programming',
29+
course_description: {
30+
content: `
31+
A technical introduction to the fundamentals of programming with an
32+
emphasis on producing clear, robust, and reasonably efficient code using
33+
top-down design, informal analysis, and effective testing and debugging.
34+
Starting from first principles, we will cover a large subset of the Python
35+
programming language, including its standard libraries and programming
36+
paradigms. We will also target numerous deployment scenarios, including
37+
standalone programs, shell scripts, and web-based applications. This
38+
course assumes no prior programming experience.
39+
`,
40+
syllabus: 'The syllabus is here.'
41+
},
42+
instructor_ids: [],
43+
hidden: false,
44+
disabled: false,
45+
featured: true,
46+
labs: []
47+
},
48+
{
49+
course_number: '15-122',
50+
course_name: 'Principles of Imperative Computation',
51+
course_description: {
52+
content: `
53+
This course teaches imperative programming and methods for ensuring the
54+
correctness of programs. It is intended for students with a basic
55+
understanding of programming (variables, expressions, loops, arrays,
56+
functions). Students will learn the process and concepts needed to go
57+
from high-level descriptions of algorithms to correct imperative
58+
implementations, with specific applications to basic data structures
59+
and algorithms. Much of the course will be conducted in a subset of C
60+
amenable to verification, with a transition to full C near the end.
61+
`,
62+
syllabus: 'The syllabus is here.'
63+
},
64+
instructor_ids: [],
65+
hidden: false,
66+
disabled: false,
67+
featured: true,
68+
labs: []
69+
},
70+
{
71+
course_number: '15-150',
72+
course_name: 'Principles of Functional Programming',
73+
course_description: {
74+
content: `
75+
Upon completion of this course, students will have acquired a mastery of
76+
basic functional programming techniques, including the design of programs
77+
using types, the development of programs using mathematical techniques
78+
for verification and analysis, the use of abstract types and modules to
79+
structure code, and the exploitation of parallelism in applications.
80+
`,
81+
syllabus: 'The syllabus is here.'
82+
},
83+
instructor_ids: [],
84+
hidden: false,
85+
disabled: false,
86+
featured: true,
87+
labs: []
88+
},
89+
{
90+
course_number: '15-251',
91+
course_name: 'Great Theoretical Ideas for Computer Scientists',
92+
course_description: {
93+
content: `
94+
This course is about how to use theoretical ideas to formulate and solve
95+
problems in computer science. It integrates mathematical material with
96+
general problem solving techniques and computer science applications.
97+
Examples are drawn from algorithms, complexity theory, game theory,
98+
probability theory, graph theory, automata theory, algebra, cryptography,
99+
and combinatorics. Assignments involve both mathematical proofs and
100+
programming.
101+
`,
102+
syllabus: 'The syllabus is here.'
103+
},
104+
instructor_ids: [],
105+
hidden: false,
106+
disabled: false,
107+
featured: true,
108+
labs: []
109+
}
110+
]

tests/example_data/labs/labs.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/**
2+
Example Labs
3+
**/
4+
5+
// Import Labfiles
6+
var labfile = [];
7+
labfile[0] = require('fs').readFileSync('./lab.good.1.js', "utf8").toString();
8+
9+
// Export Labs
10+
module.exports = [
11+
{
12+
course_id : course_id,
13+
lab_name: "Getting Started with Git",
14+
file: labfile[0],
15+
tasks: [
16+
{
17+
_id: 1,
18+
updated: 1467995862937,
19+
name: "Git Clone",
20+
md: "##################"
21+
},
22+
{
23+
_id: 2,
24+
updated: 1467995862937,
25+
name: "Git Pull",
26+
md: "##################"
27+
}
28+
]
29+
}
30+
]

tests/tuxlab.db.js

Lines changed: 21 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
Tests Meteor DB Schema
33
**/
44

5+
// Dependencies
6+
var async = require('async');
7+
58
/**
69
Insert Example Data for Testing
710
**/
@@ -21,88 +24,34 @@ describe('Database Schema', function(){
2124
});
2225

2326
// Create Example Course
24-
var course_id;
2527
it('should include courses', function(){
26-
return server.promise(function(resolve, reject){
27-
var example_course = {
28-
course_number: "15-131",
29-
course_name: "Great Practical Ideas for Computer Scientists",
30-
course_description: {
31-
content: "This is the course description for 15-131.",
32-
syllabus: 'This is the course syllabus.'
33-
},
34-
instructor_ids: [], // Add instructor Id here
35-
hidden: false,
36-
featured: true,
37-
labs: []
38-
}
28+
return server.execute(function(){
3929

40-
Collections.courses.insert(example_course, function(err, id){
41-
if(err){
42-
reject(err);
43-
}
44-
else{
45-
resolve(id);
46-
}
30+
// Create Courses
31+
var courses = require('example_data/courses/courses.js');
32+
async.map(courses, function(course, callback){
33+
Collections.courses.insert(course, callback);
34+
}, function(err, results){
35+
expect(err).to.be.null;
4736
});
48-
}).then(function(id){
49-
course_id = id;
37+
5038
});
5139
});
5240

53-
// Create Example Lab
54-
var lab_id;
41+
// Create Example Labs
5542
it('should include labs', function(){
43+
return server.execute(function(){
5644

57-
var labfile = require('fs').readFileSync('./tests/example_data/labfile1.js', "utf8").toString();
58-
59-
return server.promise(function(resolve, reject, labfile, course_id){
60-
var example_lab = {
61-
course_id : course_id,
62-
lab_name: "Getting Started with Git",
63-
file: labfile,
64-
tasks: [
65-
{
66-
_id: 1,
67-
updated: 1467995862937,
68-
name: "Git Clone",
69-
md: "##################"
70-
},
71-
{
72-
_id: 2,
73-
updated: 1467995862937,
74-
name: "Git Pull",
75-
md: "##################"
76-
}
77-
]
78-
}
79-
80-
Collections.labs.insert(example_lab, function(err, id){
81-
if(err){
82-
reject(err);
83-
}
84-
else{
85-
resolve(id);
86-
}
45+
// Create Labs
46+
var labs = require('example_data/labs/labs.js');
47+
async.map(labs, function(lab, callback){
48+
Collections.courses.insert(lab, callback);
49+
}, function(err, results){
50+
expect(err).to.be.null;
8751
});
88-
}, [labfile, course_id]).then(function(id){
89-
lab_id = id;
52+
9053
});
9154
});
9255

93-
// Validate that Records Exists
94-
it('should be accepted by database', function(){
95-
return server.execute(function(course_id, lab_id){
96-
var course = Collections.courses.findOne(course_id);
97-
98-
// Check Lab Injection
99-
expect(course).to.have.property('labs');
100-
expect(course.labs).to.include(lab_id);
101-
102-
var lab = Collections.labs.findOne(lab_id);
103-
104-
// Confirm LabFile verifications were run
105-
106-
}, [course_id, lab_id]);
107-
});
56+
10857
});

tests/tuxlab.user.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/**
2+
Test User Functionality
3+
**/
4+
5+
//TODO Create Example User
6+
7+
//TODO Enroll Example User in Courses
8+
9+
//TODO Test Site Authorization

0 commit comments

Comments
 (0)