Skip to content

Commit

Permalink
added pagination test for public /sessions endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
bplcensys committed Sep 30, 2022
1 parent e6c141d commit 1dd145f
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions session/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -559,6 +559,31 @@ func TestHandlerSelfServiceSessionManagement(t *testing.T) {
}
}

t.Run("case=list should return pagination headers", func(t *testing.T) {
client, i, _ := setup(t)

// Make some stubbed sessions
sess := make([]Session, 2)
for j := range sess {
require.NoError(t, faker.FakeData(&sess[j]))
sess[j].Identity = i
require.NoError(t, reg.SessionPersister().UpsertSession(ctx, &sess[j]))
}

req, _ := http.NewRequest("GET", ts.URL+"/sessions", nil)
res, err := client.Do(req)
require.NoError(t, err)
require.Equal(t, http.StatusOK, res.StatusCode)

// Make sure the response is valid json, just as a sanity check
var sessions []Session
require.NoError(t, json.NewDecoder(res.Body).Decode(&sessions))

// Make sure the pagination headers are on the response
require.Equal(t, "2", res.Header.Get("X-Total-Count"))
require.NotEqual(t, "", res.Header.Get("Link")) // Just make sure the Link header isn't empty
})

t.Run("case=should return 200 and number after invalidating all other sessions", func(t *testing.T) {
client, i, currSess := setup(t)

Expand Down

0 comments on commit 1dd145f

Please sign in to comment.