forked from nullp2ike/tutorid
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBookingConfirmationChecks.java
More file actions
100 lines (74 loc) · 4.8 KB
/
BookingConfirmationChecks.java
File metadata and controls
100 lines (74 loc) · 4.8 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
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 BookingConfirmationChecks {
//5
@Test
public void Tutor_ConfirmsBooking_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 confirmBookingResponse = new BookingRequest().confirm(tutor.getCookieFilter(), tutor.getNickname(), requestId);
final String bookingEventStatus = new JSONObject(confirmBookingResponse.getBody().asString()).getJSONObject("data").getJSONArray("instances").getJSONObject(0).getString("bookingEventStatus");
assertThat(bookingEventStatus).isEqualTo("confirmed");
}
//6
@Test
void Student_ConfirmsBooking_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 confirmBookingResponse = new BookingRequest().confirm(student.getCookieFilter(), tutor.getNickname(), requestId);
final String bookingEventStatus = new JSONObject(confirmBookingResponse.getBody().asString()).getJSONObject("data").getJSONArray("instances").getJSONObject(0).getString("bookingEventStatus");
assertThat(bookingEventStatus).isEqualTo("confirmed");
}
//7
@Test
public void Student_RequestsBookingAndTutorConfirm_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 BookingRequestBuilder builder = new DefaultBookingData().tutorScheduled(tutor, student);
final int requestId = new JSONObject(bookingRequestResponse.getBody().asString()).getJSONArray("data").getJSONObject(0).getInt("id");
final Response confirmBookingResponse = new BookingRequest(builder).confirm(tutor.getCookieFilter(), tutor.getNickname(), requestId);
final String bookingEventStatus = new JSONObject(confirmBookingResponse.getBody().asString()).getJSONObject("data").getJSONArray("instances").getJSONObject(0).getString("bookingEventStatus");
assertThat(bookingEventStatus.equals("confirmed"));
}
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));
}
}