Skip to content

Commit

Permalink
GH-98: Added failing test recreating the bug.
Browse files Browse the repository at this point in the history
  • Loading branch information
jirenius committed Jul 31, 2019
1 parent dd6d21c commit aab95e0
Showing 1 changed file with 34 additions and 3 deletions.
37 changes: 34 additions & 3 deletions test/10reaccess_event_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func TestReaccessEvent(t *testing.T) {
})
}

// Test that a reaccess event triggers a re-access call on subscribed resources
// Test that a reaccess event triggers a new access call on subscribed resources
// and that the resource are still subscribed after given access
func TestReaccessEventTriggersAccessCallOnSubscribedResources(t *testing.T) {
runTest(t, func(s *Session) {
Expand Down Expand Up @@ -53,8 +53,8 @@ func TestReaccessEventTriggersAccessCallOnSubscribedResources(t *testing.T) {
})
}

// Test that a reaccess event triggers a re-access call on subscribed resources
// and that the resource are unsubscribed after being deniedn access
// Test that a reaccess event triggers a new access call on subscribed resources
// and that the resource are unsubscribed after being denied access
func TestReaccessEventTriggersUnsubscribeOnDeniedAccessCall(t *testing.T) {
runTest(t, func(s *Session) {
event := json.RawMessage(`{"foo":"bar"}`)
Expand Down Expand Up @@ -83,3 +83,34 @@ func TestReaccessEventTriggersUnsubscribeOnDeniedAccessCall(t *testing.T) {
c.AssertNoEvent(t, "test.model.parent")
})
}

// Test that unsubscribing a parent resource triggers a new access call on the child.
func TestUnsubscribingParentTriggersAccessCall(t *testing.T) {
runTest(t, func(s *Session) {
event := json.RawMessage(`{"foo":"bar"}`)

c := s.Connect()

// Get linked model
subscribeToTestModelParent(t, s, c, false)

// Subscribe to child
c.Request("subscribe.test.model", nil).GetResponse(t).AssertResult(t, json.RawMessage(`{}`))

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

// Assert we get a new access request on child model
req := s.GetRequest(t).AssertSubject(t, "access.test.model.parent")

// Send event on model and validate no client event
s.ResourceEvent("test.model", "custom", event)
c.AssertNoEvent(t, "test.model")

// Respond with access
req.RespondSuccess(json.RawMessage(`{"get":true}`))

// Assert that the event is now sent
c.GetEvent(t).Equals(t, "test.model.custom", event)
})
}

0 comments on commit aab95e0

Please sign in to comment.