diff --git a/src/collection.js b/src/collection.js index 7678c2c2..58ec9e11 100644 --- a/src/collection.js +++ b/src/collection.js @@ -1,6 +1,6 @@ import { v4 as uuid } from "uuid"; -import { capable, toDataBody, isObject } from "./utils"; +import { capable, toDataBody, isObject, qsify } from "./utils"; import * as requests from "./requests"; import endpoint from "./endpoint"; @@ -79,13 +79,19 @@ export default class Collection { * * @param {Object} [options={}] The options object. * @param {Object} [options.headers] The headers object option. + * @param {String} [options.since] The since ETag option. * @return {Promise} */ getTotalRecords(options={}) { - const { headers } = this._collOptions(options); + const { since, ...otherOptions } = options; + const { headers } = this._collOptions(otherOptions); + let path = endpoint("record", this.bucket.name, this.name); + if (since) { + path += "?" + qsify({since}); + } return this.client.execute({ method: "HEAD", - path: endpoint("record", this.bucket.name, this.name), + path, headers }, {raw: true}) .then(({headers}) => parseInt(headers.get("Total-Records"), 10)); diff --git a/test/collection_test.js b/test/collection_test.js index 65865b27..08db2b22 100644 --- a/test/collection_test.js +++ b/test/collection_test.js @@ -54,6 +54,18 @@ describe("Collection", () => { return getBlogPostsCollection().getTotalRecords() .should.become(42); }); + + it("should pass the since parameter", () => { + sandbox.stub(client, "execute").returns(Promise.resolve()); + + getBlogPostsCollection().getTotalRecords({since: "ETAG"}); + + sinon.assert.calledWithMatch(client.execute, { + method: "HEAD", + path: "/buckets/blog/collections/posts/records?since=ETAG", + }, {raw: true}); + }); + }); /** @test {Collection#getData} */