Skip to content

Commit

Permalink
Added test: TestUnsubscribe_FollowedByResourceResponse_IncludesResource
Browse files Browse the repository at this point in the history
  • Loading branch information
jirenius committed May 27, 2020
1 parent 6743535 commit 0aa81eb
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions test/03unsubscribe_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,3 +159,57 @@ func TestUnsubscribeOnOverlappingLinkedCollection(t *testing.T) {
c.GetEvent(t).Equals(t, "test.collection.secondparent.custom", event)
})
}

func TestUnsubscribe_FollowedByResourceResponse_IncludesResource(t *testing.T) {
runTest(t, func(s *Session) {
c := s.Connect()
model := resourceData("test.model")

// Send subscribe request
creq := c.Request("subscribe.test.model", nil)
// Handle model get and access request
mreqs := s.GetParallelRequests(t, 2)
mreqs.GetRequest(t, "get.test.model").RespondSuccess(json.RawMessage(`{"model":` + model + `}`))
req := mreqs.GetRequest(t, "access.test.model")
req.RespondSuccess(json.RawMessage(`{"get":true}`))

// Validate client response and validate
creq.GetResponse(t).AssertResult(t, json.RawMessage(`{"models":{"test.model":`+model+`}}`))

// Send client request
creq = c.Request("call.test.getModel", nil)
req = s.GetRequest(t)
req.AssertSubject(t, "access.test")
req.RespondSuccess(json.RawMessage(`{"get":true,"call":"*"}`))
// Get call request
req = s.GetRequest(t)
req.AssertSubject(t, "call.test.getModel")
req.RespondResource("test.model")
// Validate client response
cresp := creq.GetResponse(t)
cresp.AssertResult(t, json.RawMessage(`{"rid":"test.model"}`))

// Call unsubscribe
c.Request("unsubscribe.test.model", nil).GetResponse(t)

// Call unsubscribe
c.Request("unsubscribe.test.model", nil).GetResponse(t)

// Send client request
creq = c.Request("call.test.getModel", nil)
req = s.GetRequest(t)
req.AssertSubject(t, "access.test")
req.RespondSuccess(json.RawMessage(`{"get":true,"call":"*"}`))
// Get call request
req = s.GetRequest(t)
req.AssertSubject(t, "call.test.getModel")
req.RespondResource("test.model")
// Access request
req = s.GetRequest(t)
req.AssertSubject(t, "access.test.model")
req.RespondSuccess(json.RawMessage(`{"get":true}`))
// Validate client response
cresp = creq.GetResponse(t)
cresp.AssertResult(t, json.RawMessage(`{"rid":"test.model","models":{"test.model":`+model+`}}`))
})
}

0 comments on commit 0aa81eb

Please sign in to comment.