This repository has been archived by the owner on Sep 17, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest.rb
249 lines (220 loc) · 8.92 KB
/
test.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
require 'simplecov'
SimpleCov.start
require_relative './service'
require_relative './serviceProvider'
require_relative './appointment'
require_relative './timeblock'
require_relative './print'
require_relative './init'
require_relative './colors'
require_relative './availability'
require 'date'
require 'launchy'
RSpec.describe ServiceProvider do
describe "#serviceAdd" do
describe "add service that sp does not have" do
it "should add service to sp's services" do
sp = ServiceProvider.new("waluigi", 1111111111, [], [], [])
serv = Service.new("hugs", 0, 180)
sp.service_add(serv)
expect(sp.services.include?(serv)).to eq(true)
end
end
end
describe "#serviceRemove" do
describe "remove service that sp has" do
it "should remove service from sp's services" do
sp = ServiceProvider.new("waluigi", 1111111111, [], [], [])
serv1 = Service.new("hugs", 0, 180)
serv2 = Service.new("shrugs", 3, 60)
sp.service_add(serv1)
sp.service_add(serv2)
sp.service_remove(serv1.name)
expect(sp.services.include?(serv1)).to eq(false)
end
end
describe "sp does not have service" do
it "should do nothing" do
sp = ServiceProvider.new("waluigi", 1111111111, [], [], [])
serv1 = Service.new("hugs", 0, 180)
serv2 = Service.new("shrugs", 3, 60)
sp.service_add(serv1)
test_services_length = 1
sp.service_remove(serv2.name)
expect(sp.services.length).to eq(test_services_length)
end
end
end
describe "#containsService" do
describe "check service that sp has" do
it "returns true" do
sp = ServiceProvider.new("waluigi", 1111111111, [], [], [])
serv1 = Service.new("hugs", 0, 180)
sp.service_add(serv1)
expect(sp.contains_service(serv1.name)).to eq(serv1)
end
end
describe "check service that sp does not have" do
it "returns false" do
sp = ServiceProvider.new("waluigi", 1111111111, [], [], [])
serv1 = Service.new("hugs", 0, 180)
serv2 = Service.new("shrugs", 3, 60)
sp.service_add(serv1)
expect(sp.contains_service(serv2.name)).to eq(false)
end
end
end
describe "#add_availability" do
describe "add availability that sp does not have" do
it "should add availability to sp's availability" do
sp = ServiceProvider.new("waluigi", 1111111111, [], [], [])
av = TimeBlock.new(DateTime.new(2019, 12, 12, 12), false, 120)
sp.add_availability(av)
expect(sp.availability.include?(av)).to eq(true)
end
end
end
describe "#is_available" do
describe "no conflicts with appointments" do
it "should return true" do
sp = ServiceProvider.new("waluigi", 1111111111, [], [], [])
serv1 = Service.new("hugs", 0, 180)
serv2 = Service.new("shrugs", 3, 60)
sp.service_add(serv1)
sp.service_add(serv2)
tb1 = TimeBlock.new(DateTime.new(2019, 12, 12, 12), false, 120)
tb2 = TimeBlock.new(DateTime.new(2019, 11, 11, 11), false, 120)
sp.add_appointment(serv1, tb1, 'bill')
expect(sp.is_available(serv2, tb2, false)).to eq(true)
end
end
describe "conflict with appointments" do
it "should return false" do
sp = ServiceProvider.new("waluigi", 1111111111, [], [], [])
serv1 = Service.new("hugs", 0, 180)
serv2 = Service.new("shrugs", 3, 60)
sp.service_add(serv1)
sp.service_add(serv2)
tb1 = TimeBlock.new(DateTime.new(2019, 12, 12, 12), false, 120)
sp.add_appointment(serv1, tb1, 'bill')
expect(sp.is_available(serv2, tb1, false)).to eq(false)
end
end
# describe "no conflicts with availability" do
# it "should return true" do
# sp = ServiceProvider.new("waluigi", 1111111111, [], [], [])
# av = TimeBlock.new(DateTime.new(2019, 12, 12, 12), false, 120)
# sp.add_availability(av)
# end
# end
# describe "conflict with availability" do
# it "should return false" do
# sp = ServiceProvider.new("waluigi", 1111111111, [], [], [])
# av = TimeBlock.new(DateTime.new(2019, 12, 12, 12), false, 120)
# sp.add_availability(av)
# end
# end
end
describe "#add_appointment" do
describe "add appointment with no conflicts" do
it "should add appointment to sp's appointments" do
sp = ServiceProvider.new("waluigi", 1111111111, [], [], [])
serv1 = Service.new("hugs", 0, 180)
sp.service_add(serv1)
tb1 = TimeBlock.new(DateTime.new(2019, 12, 12, 12), false, 120)
tb2 = TimeBlock.new(DateTime.new(2019, 11, 11, 11), false, 120)
sp.add_appointment(serv1, tb1, 'bill')
expect(sp.add_appointment(serv1, tb2, 'bill')).to eq(true)
end
end
describe "add appointment with conflicts" do
it "should print an error message and return false" do
sp = ServiceProvider.new("waluigi", 1111111111, [], [], [])
serv1 = Service.new("hugs", 0, 180)
serv2 = Service.new("shrugs", 3, 60)
sp.service_add(serv1)
sp.service_add(serv2)
tb1 = TimeBlock.new(DateTime.new(2019, 12, 12, 12), false, 120)
sp.add_appointment(serv1, tb1, 'bill')
expect(sp.add_appointment(serv2, tb1, 'bill')).to eq(false)
end
end
end
end
RSpec.describe Service do
describe "#printDetails" do
it "prints details of service" do
service_providers = initData
service = service_providers[0].services[0]
new_service = Service.new(service.name, service.price, service.length)
expect(new_service.print_details).to eq([service.name, service.price.to_s, service.length.to_s])
end
end
end
RSpec.describe Availability do
describe "#printDetails" do
it "prints details of availability" do
service_providers = initData
service_provider = service_providers[0]
datetime1 = DateTime.new(2019, 12, 12, 12)
timeblock = TimeBlock.new(datetime1, false, 120)
new_availability = Availability.new(timeblock, timeblock, service_provider)
expect(new_availability.print_details).to eq(["12", "12", "2019", "12:00:00", "14:00:00", "false"])
end
end
end
RSpec.describe TimeBlock do
describe "#contains" do
it "checks if a timeblock contains another time block " do
datetime1 = DateTime.new(2019, 12, 12, 12)
timeblock = TimeBlock.new(datetime1, false, 120)
expect(timeblock.contains(timeblock)).to eq(true)
end
end
describe "#contains_time" do
it "check if a timeblock contains another time block regardless of date" do
datetime1 = DateTime.new(2019, 12, 12, 12)
timeblock = TimeBlock.new(datetime1, false, 120)
datetime2 = DateTime.new(2019, 11, 12, 12)
timeblock2 = TimeBlock.new(datetime1, false, 120)
expect(timeblock.contains_time(timeblock2)).to eq(true)
end
end
describe "#overlaps" do
it "checks if two timeblocks overlap" do
datetime1 = DateTime.new(2019, 12, 12, 12)
timeblock = TimeBlock.new(datetime1, false, 120)
expect(timeblock.overlaps(timeblock)).to eq(true)
end
end
describe "#overlaps_time" do
it "checks if two timeblocks overlap, no matter the date" do
datetime1 = DateTime.new(2019, 12, 12, 12)
timeblock = TimeBlock.new(datetime1, false, 120)
datetime2 = DateTime.new(2019, 11, 12, 12)
timeblock2 = TimeBlock.new(datetime1, false, 120)
expect(timeblock.overlaps_time(timeblock2)).to eq(true)
end
end
describe "#printDetails" do
it "prints details of timeblock" do
datetime1 = DateTime.new(2019, 12, 12, 12)
timeblock = TimeBlock.new(datetime1, false, 120)
expect(timeblock.print_details).to eq(["12", "12", "2019", "12:00:00", "14:00:00", "14:00:00"])
end
end
describe "" do
it "" do
end
end
end
RSpec.describe ServiceProvider do
describe "#printDetails" do
it "prints details of Appointment" do
datetime1 = DateTime.new(2019, 12, 12, 12)
appointment1 = Appointment.new(TimeBlock.new(datetime1, false, 120), Service.new('Helping', 200, 60), 'Larry', ServiceProvider.new('Jim', '1111111111', [Service.new('Helping', 200, 60)], [], []))
expect(appointment1.print_details).to eq("Thursday")
end
end
end
Launchy::Browser.run("./coverage/index.html")