Skip to content

Commit

Permalink
Added EventUpdates
Browse files Browse the repository at this point in the history
  • Loading branch information
KlausSchaefers committed Feb 22, 2024
1 parent 86b5967 commit f949e3b
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 6 deletions.
1 change: 1 addition & 0 deletions src/main/java/com/qux/MATC.java
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,7 @@ private void initEventRest(Router router) {
router.route(HttpMethod.GET, "/rest/events/:appID/:session.json").handler(event.findBy());
router.route(HttpMethod.GET, "/rest/events/:appID/all/count.json").handler(event.countBy());
router.route(HttpMethod.DELETE, "/rest/events/:appID/:session.json").handler(event.deleteBy());
router.route(HttpMethod.POST, "/rest/events/:appID/:id.json").handler(event.update());

MouseRest mouse = new MouseRest(this.tokenService, client);
mouse.setBatch(true);
Expand Down
11 changes: 8 additions & 3 deletions src/main/java/com/qux/acl/EventAcl.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,17 @@ public void canRead(User user, RoutingContext event,Handler<Boolean> handler) {
}

}

@Override
public void canWrite(User user, RoutingContext event, Handler<Boolean> handler) {
handler.handle(false);
if(user.hasRole(User.USER)){
String appID = event.request().params().get("appID");
client.count(team_db, Team.canWrite(user, appID), res->{
assertOne(res, handler, event);
});
} else {
handler.handle(false);
}
}

@Override
public void canDelete(User user, RoutingContext event, Handler<Boolean> handler) {
if(user.hasRole(User.USER)){
Expand Down
53 changes: 50 additions & 3 deletions src/test/java/com/qux/EventRestTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.qux.model.App;
import com.qux.util.rest.MongoREST;
import io.vertx.core.json.JsonArray;
import io.vertx.core.json.JsonObject;
import io.vertx.ext.unit.TestContext;
import io.vertx.ext.unit.junit.VertxUnitRunner;
Expand All @@ -13,7 +14,44 @@

@RunWith(VertxUnitRunner.class)
public class EventRestTest extends MatcTestCase {


@Test
public void testUpdate(TestContext context){
log("testUpdate", "enter");


cleanUp();

deploy(new MATC(), context);

/**
* create user & app
*/
postUser("klaus", context);
assertLogin(context, "[email protected]", "123456789");
App klaus_app_public = postApp("klaus_private", false, context);

/**
* add events
*/

postEvent(klaus_app_public, "session", "SessionStart", context);

JsonArray events = assertList("/rest/events/" + klaus_app_public.getId() +".json", 1, context);
context.assertEquals(1, events.size());

JsonObject event = events.getJsonObject(0);
event.put("label", "ABC");
updateEvent(klaus_app_public, event.getString("id"), event, context);

events = assertList("/rest/events/" + klaus_app_public.getId() +".json", 1, context);
context.assertEquals(1, events.size());
event = events.getJsonObject(0);
context.assertEquals("ABC", event.getString("label"));


log("testBatch", "exit");
}


@Test
Expand All @@ -29,7 +67,7 @@ public void testParseQuery(TestContext context){
context.assertEquals(2, result.size());
context.assertEquals("Animation", result.get("exclude"));
context.assertEquals("true", result.get("batch"));

result = MongoREST.parseQuery("batch=true&exclude=Animation");
context.assertEquals(2, result.size());
context.assertEquals("Animation", result.get("exclude"));
Expand Down Expand Up @@ -238,7 +276,16 @@ public void deleteSession(App app, String session, TestContext context){
context.assertTrue(!result.containsKey("errors"));

}


public void updateEvent(App app, String id, JsonObject event, TestContext context){
JsonObject result = post("/rest/events/" + app.getId() + "/" + id +".json", event);
log("updateEvent", ""+result);
context.assertTrue(!result.containsKey("error"));
context.assertTrue(!result.containsKey("errors"));
}



public void postEventError(App app, String session, String type, TestContext context){
JsonObject event = new JsonObject()
.put("session", session)
Expand Down

0 comments on commit f949e3b

Please sign in to comment.