scimmyjs / scimmy

SCIM m(ade eas)y - SCIM 2.0 library for NodeJS
https://scimmyjs.github.io
MIT License
41 stars 10 forks source link

ListResponse not paginating as expected #21

Closed sleelin closed 6 months ago

sleelin commented 6 months ago

Currently, ListResponse will paginate the results only when the length of the supplied resources array is greater than the supplied itemsPerPage value, which defaults to 20. This process does not take into account a supplied startIndex, meaning more results will be included in a page than expected when totalResults is less than itemsPerPage, effectively ignoring startIndex.

Steps to reproduce: Instantiate a new ListResponse with a specified startIndex and fewer resources than itemsPerPage

new ListResponse(new Array(11).fill({}).map((_, i) => ({index: i+1})), {startIndex: 10, itemsPerPage: 11});

Expected behaviour: Resources in the ListResponse should begin from the supplied startIndex

ListResponse {
  schemas: [ 'urn:ietf:params:scim:api:messages:2.0:ListResponse' ],
  totalResults: 11,
  Resources: [
    { index: 11 }
  ],
  startIndex: 10,
  itemsPerPage: 20
}

Actual behaviour: All resources are included in the ListResponse, and startIndex is ignored

ListResponse {
  schemas: [ 'urn:ietf:params:scim:api:messages:2.0:ListResponse' ],
  totalResults: 11,
  Resources: [
    { index: 1 },  { index: 2 },
    { index: 3 },  { index: 4 },
    { index: 5 },  { index: 6 },
    { index: 7 },  { index: 8 },
    { index: 9 },  { index: 10 },
    { index: 11 }
  ],
  startIndex: 10,
  itemsPerPage: 20
}