forked from nullp2ike/tutorid
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAvailability.java
More file actions
52 lines (41 loc) · 1.96 KB
/
Availability.java
File metadata and controls
52 lines (41 loc) · 1.96 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
package requests;
import java.time.Instant;
import java.time.temporal.ChronoUnit;
import org.apache.http.HttpStatus;
import org.json.JSONArray;
import org.json.JSONObject;
import groovy.json.internal.Chr;
import io.restassured.http.ContentType;
import io.restassured.response.Response;
import utils.Setup;
import utils.domain.Tutor;
import static io.restassured.RestAssured.given;
public class Availability {
private String startDateTime;
private String endDateTime;
private final JSONObject availability;
public Availability(){
this.availability = new JSONObject();
}
public Availability tomorrowFromNow1H(){
final Instant tomorrow = Instant.now().truncatedTo(ChronoUnit.HOURS).plus(1, ChronoUnit.DAYS);
this.availability.put("startDateTime", tomorrow.toString());
this.availability.put("endDateTime", tomorrow.plus(1, ChronoUnit.HOURS).toString());
return this;
}
public Response add(final Tutor tutor){
this.availability.put("discount", 0);
this.availability.put("privateLocationIds",new JSONArray().put(tutor.getPrivateLocations().get(0).getId()));
this.availability.put("publicLocationIds", new JSONArray().put(tutor.getPublicLocations().get(0).getId()));
this.availability.put("recurrenceRule","RRULE:FREQ=DAILY;COUNT=1");
this.availability.put("studentsPlaceAllowed", true);
this.availability.put("onlineLocationsAllowed", true);
final Response response = given().filter(tutor.getCookieFilter())
.contentType(ContentType.JSON)
.body(this.availability.toString())
.when()
.post(Setup.usersUrl + "/" + tutor.getNickname() + "/calendar/availability/events");
response.then().statusCode(HttpStatus.SC_OK);
return response;
}
}