Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Avatar for KuCalc : devops.
Download
50640 views
1
{available_upgrades, current_student_project_upgrades, upgrade_plan} = require('../project-upgrades')
2
3
immutable = require('immutable')
4
5
misc = require('smc-util/misc')
6
7
expect = require('expect')
8
9
describe 'test the available_upgrades function -- ', ->
10
account_id = misc.uuid()
11
it 'a very basic example', ->
12
x = available_upgrades
13
account_id : account_id
14
purchased_upgrades : {} # nothing bought
15
project_map : immutable.Map() # no projects
16
student_project_ids : {}
17
expect(x).toEqual({})
18
19
it 'example with some upgrades but no projects', ->
20
x = available_upgrades
21
account_id : account_id
22
purchased_upgrades : {disk:5, widgets:10}
23
project_map : immutable.Map()
24
student_project_ids : {}
25
expect(x).toEqual({disk:5, widgets:10})
26
27
it 'example with a project having nothing to do with the course', ->
28
project_id = misc.uuid()
29
x = available_upgrades
30
account_id : account_id
31
purchased_upgrades : {disk:5, widgets:10}
32
project_map : immutable.fromJS({"#{project_id}": {users:{"#{account_id}":{upgrades:{disk:2,widgets:3}}}}})
33
student_project_ids : {}
34
expect(x).toEqual({disk:3, widgets:7})
35
36
it 'example with a project in the course', ->
37
project_id = misc.uuid()
38
x = available_upgrades
39
account_id : account_id
40
purchased_upgrades : {disk:5, widgets:10}
41
project_map : immutable.fromJS({"#{project_id}": {users:{"#{account_id}":{upgrades:{disk:2,widgets:3}}}}})
42
student_project_ids : {"#{project_id}": true, "#{misc.uuid()}":true}
43
expect(x).toEqual({disk:5, widgets:10})
44
45
it 'example with a project in the course and one not', ->
46
project_id = misc.uuid()
47
project2_id = misc.uuid()
48
x = available_upgrades
49
account_id : account_id
50
purchased_upgrades : {disk:5, widgets:10}
51
project_map : immutable.fromJS({"#{project_id}": {users:{"#{account_id}":{upgrades:{disk:2,widgets:3}}}}, "#{project2_id}": {users:{"#{account_id}":{upgrades:{disk:2,widgets:3}}}}})
52
student_project_ids : {"#{project_id}": true, "#{misc.uuid()}":true}
53
expect(x).toEqual({disk:3, widgets:7})
54
55
describe 'test the current_student_project_upgrades function -- ', ->
56
account_id = misc.uuid()
57
it 'a very basic example', ->
58
x = current_student_project_upgrades
59
account_id : account_id
60
project_map : immutable.Map() # no projects
61
student_project_ids : {}
62
expect(x).toEqual({})
63
64
it 'a project having nothing to do with the course', ->
65
project_id = misc.uuid()
66
x = current_student_project_upgrades
67
account_id : account_id
68
project_map : immutable.fromJS({"#{project_id}": {users:{"#{account_id}":{upgrades:{disk:2,widgets:3}}}}})
69
student_project_ids : {}
70
expect(x).toEqual({})
71
72
it 'a project in the course with upgrades only from account_id shows nothing', ->
73
project_id = misc.uuid()
74
x = current_student_project_upgrades
75
account_id : account_id
76
project_map : immutable.fromJS({"#{project_id}": {users:{"#{account_id}":{upgrades:{disk:2,widgets:3}}}}})
77
student_project_ids : {"#{project_id}": true, "#{misc.uuid()}":true}
78
expect(x).toEqual({})
79
80
it 'a project in the course with upgrades from two other users (and course owner)', ->
81
project_id = misc.uuid()
82
account_id2 = misc.uuid()
83
account_id3 = misc.uuid()
84
x = current_student_project_upgrades
85
account_id : account_id
86
project_map : immutable.fromJS({"#{project_id}": {users:{"#{account_id3}":{upgrades:{disk:5,widgets:5}},"#{account_id2}":{upgrades:{disk:10,widgets:15}}, "#{account_id}":{upgrades:{disk:2,widgets:3}}}}})
87
student_project_ids : {"#{project_id}": true, "#{misc.uuid()}":true}
88
expect(x).toEqual({"#{project_id}":{disk:15,widgets:20}})
89
90
it 'example with a project in the course and one not', ->
91
project_id = misc.uuid()
92
project2_id = misc.uuid()
93
account_id2 = misc.uuid()
94
x = current_student_project_upgrades
95
account_id : account_id
96
project_map : immutable.fromJS({"#{project_id}": {users:{"#{account_id2}":{upgrades:{disk:2,widgets:3}}}}, "#{project2_id}": {users:{"#{account_id2}":{upgrades:{disk:2,widgets:3}}}}})
97
student_project_ids : {"#{project_id}": true, "#{misc.uuid()}":true}
98
expect(x).toEqual({"#{project_id}": {disk:2, widgets:3}})
99
100
101
102
103
describe 'test the upgrade_plan -- ', ->
104
account_id = misc.uuid()
105
it 'a very basic example', ->
106
plan = upgrade_plan
107
account_id : account_id
108
purchased_upgrades : {}
109
project_map : immutable.Map() # no projects
110
student_project_ids : {}
111
deleted_project_ids : {}
112
upgrade_goal : {}
113
expect(plan).toEqual({})
114
115
it 'with one student project', ->
116
project_id = misc.uuid()
117
plan = upgrade_plan
118
account_id : account_id
119
purchased_upgrades : {quota0:5, quota1:4}
120
project_map : immutable.fromJS({"#{project_id}": {users:{}}})
121
student_project_ids : {"#{project_id}": true}
122
deleted_project_ids : {}
123
upgrade_goal : {quota0:1, quota1:2}
124
expect(plan).toEqual("#{project_id}": {quota0:1, quota1:2})
125
126
it 'with two student projects', ->
127
project_id = misc.uuid()
128
project_id2 = misc.uuid()
129
plan = upgrade_plan
130
account_id : account_id
131
purchased_upgrades : {quota0:5, quota1:4}
132
project_map : immutable.fromJS({"#{project_id}": {users:{}}, "#{project_id2}": {users:{}}})
133
student_project_ids : {"#{project_id}": true, "#{project_id2}": true}
134
deleted_project_ids : {}
135
upgrade_goal : {quota0:1, quota1:2}
136
expect(plan).toEqual("#{project_id}": {quota0:1, quota1:2}, "#{project_id2}": {quota0:1, quota1:2})
137
138
it 'with one student project and one deleted student project', ->
139
project_id = misc.uuid()
140
project_id2 = misc.uuid()
141
plan = upgrade_plan
142
account_id : account_id
143
purchased_upgrades : {quota0:5, quota1:4}
144
project_map : immutable.fromJS({"#{project_id}": {users:{}}, "#{project_id2}": {users:{}}})
145
student_project_ids : {"#{project_id}": true, "#{project_id2}": true}
146
deleted_project_ids : {"#{project_id2}": true}
147
upgrade_goal : {quota0:1, quota1:2}
148
expect(plan).toEqual("#{project_id}": {quota0:1, quota1:2})
149
150
it 'with one student project with upgrades from account_id and one deleted student project that has upgrades applied by account_id, and a third project with upgrades from account_id, having nothing to do with course', ->
151
project_id = misc.uuid()
152
project_id2 = misc.uuid()
153
project_id3 = misc.uuid()
154
account_id2 = misc.uuid()
155
plan = upgrade_plan
156
account_id : account_id
157
purchased_upgrades : {quota0:5, quota1:4}
158
project_map : immutable.fromJS({"#{project_id}": {users:{"#{account_id2}":{upgrades:{quota0:1,quota1:1}}}, "#{project_id2}": {users:{"#{account_id}":{upgrades:{quota0:1,quota1:1}}}}}, "#{project_id3}":{users:{"#{account_id}":{upgrades:{quota0:1,quota1:1}}}}})
159
student_project_ids : {"#{project_id}": true, "#{project_id2}": true}
160
deleted_project_ids : {"#{project_id2}": true}
161
upgrade_goal : {quota0:1, quota1:2}
162
expect(plan).toEqual("#{project_id}": {quota1:1})
163
164
it 'with two student projects but insufficient upgrades for our goal for quota0', ->
165
project_id = '0' + misc.uuid().slice(1)
166
project_id2 = '1' + misc.uuid().slice(1)
167
plan = upgrade_plan
168
account_id : account_id
169
purchased_upgrades : {quota0:5, quota1:4}
170
project_map : immutable.fromJS({"#{project_id}": {users:{}}, "#{project_id2}": {users:{}}})
171
student_project_ids : {"#{project_id}": true, "#{project_id2}": true}
172
deleted_project_ids : {}
173
upgrade_goal : {quota0:4, quota1:3}
174
expect(plan).toEqual("#{project_id}": {quota0:4, quota1:3}, "#{project_id2}": {quota0:1, quota1:1})
175
176
177
it 'with two student projects but one is already upgraded by account_id', ->
178
project_id = '0' + misc.uuid().slice(1)
179
project_id2 = '1' + misc.uuid().slice(1)
180
plan = upgrade_plan
181
account_id : account_id
182
purchased_upgrades : {quota0:5, quota1:4}
183
project_map : immutable.fromJS({"#{project_id}": {users:{"#{account_id}":{upgrades:{quota0:1,quota1:2}}}, "#{project_id2}": {users:{}}}})
184
student_project_ids : {"#{project_id}": true, "#{project_id2}": true}
185
deleted_project_ids : {}
186
upgrade_goal : {quota0:1, quota1:2}
187
expect(plan).toEqual("#{project_id2}": {quota0:1, quota1:2})
188
189
190