forked from nullp2ike/tutorid
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBookingRequestChecks.java
More file actions
217 lines (169 loc) · 9.72 KB
/
BookingRequestChecks.java
File metadata and controls
217 lines (169 loc) · 9.72 KB
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
package tests;
import io.restassured.response.Response;
import org.apache.http.HttpStatus;
import org.json.JSONObject;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import requests.Availability;
import requests.BookingRequest;
import requests.Invite;
import utils.builders.BookingRequestBuilder;
import utils.data_generation.Any;
import utils.data_generation.DefaultBookingData;
import utils.data_generation.StudentCreator;
import utils.data_generation.TutorCreator;
import utils.domain.Student;
import utils.domain.Tutor;
import utils.junit_extensions.PropertiesExtension;
import static org.hamcrest.core.IsEqual.equalTo;
@ExtendWith(PropertiesExtension.class)
public class BookingRequestChecks {
@Test
public void Tutor_RequestsBookingOnBehalfOfStudent_Success(){
final Tutor tutor = new TutorCreator(Any.tutorUsername()).create();
final Student student = new StudentCreator(Any.studentUsername()).create();
final Response response = new BookingRequest(new DefaultBookingData().tutorScheduled(tutor, student))
.asTutor(tutor, student);
response.then()
.statusCode(HttpStatus.SC_OK)
.body("description", equalTo("Booking created"));
}
@Test
public void Tutor_RequestsBookingOnBehalfOfStudentStudentLocation_Success(){
final Tutor tutor = new TutorCreator(Any.tutorUsername()).create();
final Student student = new StudentCreator(Any.studentUsername()).create();
final Response response = new BookingRequest(new DefaultBookingData().tutorScheduledStudentLocation(tutor, student))
.asTutor(tutor, student);
response.then()
.statusCode(HttpStatus.SC_OK)
.body("description", equalTo("Booking created"));
System.out.println(response.getBody().asString());
}
@Test
public void Tutor_RequestsBookingOnBehalfOfStudentTutorLocation_Success(){
final Tutor tutor = new TutorCreator(Any.tutorUsername()).create();
final Student student = new StudentCreator(Any.studentUsername()).create();
final Response response = new BookingRequest(new DefaultBookingData().tutorScheduledTutorLocation(tutor, student))
.asTutor(tutor, student);
response.then()
.statusCode(HttpStatus.SC_OK)
.body("description", equalTo("Booking created"));
}
@Test
public void Tutor_RequestsBookingOnBehalfOfStudentPayWithCard_Success(){
final Tutor tutor = new TutorCreator(Any.tutorUsername()).create();
final Student student = new StudentCreator(Any.studentUsername()).create();
final Response response = new BookingRequest(new DefaultBookingData().tutorScheduledWithCard(tutor, student))
.asTutor(tutor, student);
response.then()
.statusCode(HttpStatus.SC_OK)
.body("description", equalTo("Booking created"));
}
@Test
public void Student_RequestsBookingViaTutorAvailableTimeSlot_Success(){
//First we create a logged in tutor and student
final Tutor tutor = new TutorCreator(Any.tutorUsername()).create();
final Student student = new StudentCreator(Any.studentUsername()).create();
//Tutor adds his/her availability for tomorrow
final Response r = new Availability().tomorrowFromNow1H().add(tutor);
r.then().body("description", equalTo("Availability created"));
//Tutor invites student to join his/her network
sendInviteAndAcceptByStudent(tutor, student);
//Stetup booking request data
final BookingRequestBuilder builder = new DefaultBookingData().bookedByStudentViaTimeSlot(tutor, student);
//Send booking request
final Response response = new BookingRequest(builder).asStudent(tutor, student);
response.then().statusCode(HttpStatus.SC_OK)
.body("description", equalTo("Booking created"));
}
@Test
public void Student_RequestsBookingViaTutorAvailableTimeSlotStudentLocation_Success(){
//First we create a logged in tutor and student
final Tutor tutor = new TutorCreator(Any.tutorUsername()).create();
final Student student = new StudentCreator(Any.studentUsername()).create();
//Tutor adds his/her availability for tomorrow
final Response r = new Availability().tomorrowFromNow1H().add(tutor);
r.then().body("description", equalTo("Availability created"));
//Tutor invites student to join his/her network
sendInviteAndAcceptByStudent(tutor, student);
//Stetup booking request data
final BookingRequestBuilder builder = new DefaultBookingData().bookedByStudentViaTimeSlotStudentLocation(tutor, student);
//Send booking request
final Response response = new BookingRequest(builder).asStudent(tutor, student);
response.then().statusCode(HttpStatus.SC_OK)
.body("description", equalTo("Booking created"));
}
@Test
public void Student_RequestsBookingViaTutorAvailableTimeSlotTutorLocation_Success(){
//First we create a logged in tutor and student
final Tutor tutor = new TutorCreator(Any.tutorUsername()).create();
final Student student = new StudentCreator(Any.studentUsername()).create();
//Tutor adds his/her availability for tomorrow
final Response r = new Availability().tomorrowFromNow1H().add(tutor);
r.then().body("description", equalTo("Availability created"));
//Tutor invites student to join his/her network
sendInviteAndAcceptByStudent(tutor, student);
//Stetup booking request data
final BookingRequestBuilder builder = new DefaultBookingData().bookedByStudentViaTimeSlotTutorLocation(tutor, student);
//Send booking request
final Response response = new BookingRequest(builder).asStudent(tutor, student);
response.then().statusCode(HttpStatus.SC_OK)
.body("description", equalTo("Booking created"));
}
@Test
public void Student_RequestsBookingViaTutorAvailableTimeSlotOnlineLocation_Success(){
//First we create a logged in tutor and student
final Tutor tutor = new TutorCreator(Any.tutorUsername()).create();
final Student student = new StudentCreator(Any.studentUsername()).create();
//Tutor adds his/her availability for tomorrow
final Response r = new Availability().tomorrowFromNow1H().add(tutor);
r.then().body("description", equalTo("Availability created"));
//Tutor invites student to join his/her network
sendInviteAndAcceptByStudent(tutor, student);
//Stetup booking request data
final BookingRequestBuilder builder = new DefaultBookingData().tutorScheduledOnlineLocation(tutor, student);
//Send booking request
final Response response = new BookingRequest(builder).asStudent(tutor, student);
response.then().statusCode(HttpStatus.SC_OK)
.body("description", equalTo("Booking created"));
}
@Test
public void Student_RequestsBookingViaTutorAvailableTimeSlotWithCard_Fail(){
//First we create a logged in tutor and student
final Tutor tutor = new TutorCreator(Any.tutorUsername()).create();
final Student student = new StudentCreator(Any.studentUsername()).create();
//Tutor adds his/her availability for tomorrow
final Response r = new Availability().tomorrowFromNow1H().add(tutor);
r.then().body("description", equalTo("Availability created"));
System.out.println(r.getBody().asString());
//Tutor invites student to join his/her network
sendInviteAndAcceptByStudent(tutor, student);
//Stetup booking request data
final BookingRequestBuilder builder = new DefaultBookingData().bookedByStudentViaTimeSlotWithCard(tutor, student);
//Send booking request
final Response response = new BookingRequest(builder).asStudent(tutor, student);
response.then().statusCode(HttpStatus.SC_OK)
.body("description", equalTo("Cannot confirm booking because the student doesn't have a card connected to their account"));
}
//8
@Test
public void Student_RequestsBookingViaTutorAvailableTimeSlot_Fail(){
final Tutor tutor = new TutorCreator(Any.tutorUsername()).create();
final Student student = new StudentCreator(Any.studentUsername()).create();
sendInviteAndAcceptByStudent(tutor, student);
final BookingRequestBuilder builder = new DefaultBookingData().bookedByStudentViaTimeSlot(tutor, student);
final Response response = new BookingRequest(builder).asStudent(tutor, student);
System.out.println(response.getBody().asString());
response.then().statusCode(HttpStatus.SC_OK)
.body("description", equalTo("Tutor policy does not allow requesting booking outside availability & booking request is outside tutor's availability or tutor already has a booking during that time"));
}
private void sendInviteAndAcceptByStudent(final Tutor tutor, final Student student) {
new Invite().send(tutor, student.getEmail());
final Response invitationLinkResponse = new Invite().invitationLink(student);
final int invitationId = new JSONObject(invitationLinkResponse.getBody().asString()).getJSONObject("data").getInt("id");
final Response acceptResponse = new Invite().accept(invitationId, student);
acceptResponse.then()
.statusCode(HttpStatus.SC_OK)
.body("success", equalTo(true));
}
}