forked from nullp2ike/tutorid
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBookingCancellationChecks.java
More file actions
126 lines (89 loc) · 6.16 KB
/
BookingCancellationChecks.java
File metadata and controls
126 lines (89 loc) · 6.16 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
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.assertj.core.api.Assertions.assertThat;
import static org.hamcrest.core.IsEqual.equalTo;
@ExtendWith(PropertiesExtension.class)
public class BookingCancellationChecks {
//1
@Test
public void Tutor_CancelsBooking_Success() {
final Tutor tutor = new TutorCreator(Any.tutorUsername()).create();
final Student student = new StudentCreator(Any.studentUsername()).create();
final Response bookingRequestResponse = new BookingRequest(new DefaultBookingData().
tutorScheduled(tutor, student)).asTutor(tutor, student);
bookingRequestResponse.then().statusCode(HttpStatus.SC_OK)
.body("description", equalTo("Booking created"));
final int requestId = new JSONObject(bookingRequestResponse.getBody().
asString()).getJSONArray("data").getJSONObject(0).getInt("id");
final Response cancelBookingResponse = new BookingRequest().decline(tutor.getCookieFilter(), tutor.getNickname(), requestId);
final String bookingEventStatus = new JSONObject(cancelBookingResponse.getBody().asString()).getJSONObject("data").getJSONArray("instances").getJSONObject(0).getString("bookingEventStatus");
assertThat(bookingEventStatus).isEqualTo("cancelledByTutor");
}
//2
@Test
void Student_CancelsBooking_Success() {
final Tutor tutor = new TutorCreator(Any.tutorUsername()).create();
final Student student = new StudentCreator(Any.studentUsername()).create();
final Response addAvailabilityResponse = new Availability().tomorrowFromNow1H().add(tutor);
addAvailabilityResponse.then().statusCode(HttpStatus.SC_OK).body("description", equalTo("Availability created"));
sendInviteAndAcceptByStudent(tutor, student);
final BookingRequestBuilder builder = new DefaultBookingData().bookedByStudentViaTimeSlot(tutor, student);
final Response bookingRequestResponse = new BookingRequest(builder).asStudent(tutor, student);
final int requestId = new JSONObject(bookingRequestResponse.getBody().asString()).getJSONArray("data").getJSONObject(0).getInt("id");
final Response cancelBookingResponse = new BookingRequest().decline(student.getCookieFilter(), tutor.getNickname(), requestId);
final String bookingEventStatus = new JSONObject(cancelBookingResponse.getBody().asString()).getJSONObject("data").getJSONArray("instances").getJSONObject(0).getString("bookingEventStatus");
assertThat(bookingEventStatus).isEqualTo("cancelledByStudent");
}
//3
@Test
void Student_DeclinesBooking_Success() {
final Tutor tutor = new TutorCreator(Any.tutorUsername()).create();
final Student student = new StudentCreator(Any.studentUsername()).create();
final Response addAvailabilityResponse = new Availability().tomorrowFromNow1H().add(tutor);
addAvailabilityResponse.then().statusCode(HttpStatus.SC_OK).body("description", equalTo("Availability created"));
final Response bookingRequestResponse = new BookingRequest(new DefaultBookingData().tutorScheduled(tutor, student)).asTutor(tutor, student);
bookingRequestResponse.then().statusCode(HttpStatus.SC_OK).body("description", equalTo("Booking created"));
final BookingRequestBuilder builder = new DefaultBookingData().tutorScheduled(tutor, student);
final int requestId = new JSONObject(bookingRequestResponse.getBody().asString()).getJSONArray("data").getJSONObject(0).getInt("id");
final Response declineBookingResponse = new BookingRequest(builder).decline(tutor.getCookieFilter(), tutor.getNickname(), requestId);
final String bookingEventStatus = new JSONObject(declineBookingResponse.getBody().asString()).getJSONObject("data").getJSONArray("instances").getJSONObject(0).getString("bookingEventStatus");
assertThat(bookingEventStatus.equals("declined"));
}
//4
@Test
void Tutor_DeclinesBooking_Success() {
final Tutor tutor = new TutorCreator(Any.tutorUsername()).create();
final Student student = new StudentCreator(Any.studentUsername()).create();
final Response bookingRequestResponse = new BookingRequest(new DefaultBookingData().bookedByStudentViaTimeSlot(tutor, student)).asStudent(tutor, student);
bookingRequestResponse.then().statusCode(HttpStatus.SC_OK).body("description", equalTo("Booking created"));
final BookingRequestBuilder builder = new DefaultBookingData().bookedByStudentViaTimeSlot(tutor, student);
final int requestId = new JSONObject(bookingRequestResponse.getBody().asString()).getJSONArray("data").getJSONObject(0).getInt("id");
final Response declineBookingResponse = new BookingRequest(builder).decline(student.getCookieFilter(), student.getNickname(), requestId);
final String bookingEventStatus = new JSONObject(declineBookingResponse.getBody().asString()).getJSONObject("data").getJSONArray("instances").getJSONObject(0).getString("bookingEventStatus");
assertThat(bookingEventStatus.equals("declined"));
}
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));
}
}