diff --git a/src/models/CollectionResponse.ts b/src/models/CollectionResponse.ts new file mode 100644 index 0000000..fcaaf9a --- /dev/null +++ b/src/models/CollectionResponse.ts @@ -0,0 +1,25 @@ +/** + * @class CollectionResponse - A generic object for responses that contain collections of objects. + */ +export class CollectionResponse { + /** + * @property {number} count - The total count of items in the collection. + */ + public count: number; + + /** + * @property {T} items - The items in the collection. + */ + public items: T; + + /** + * @constructor - Creates a new instance of the CollectionResponse class. + * @param {number} count - The total count of items in the collection. + * @param {T} items - The items in the collection. + * @returns {CollectionResponse} - A new instance of the CollectionResponse. + */ + constructor(count: number, items: T) { + this.count = count; + this.items = items; + } +} diff --git a/tests/CollectionResponse.spec.ts b/tests/CollectionResponse.spec.ts new file mode 100644 index 0000000..7b2e591 --- /dev/null +++ b/tests/CollectionResponse.spec.ts @@ -0,0 +1,38 @@ +import { expect } from 'chai'; +import { CollectionResponse } from '../src/models/CollectionResponse'; + +describe('CollectionResponse', function () { + it('should be defined', function () { + expect(CollectionResponse).to.not.be.undefined; + }); + + it('should have a constructor', function () { + expect(CollectionResponse).to.have.property('constructor'); + }); + + it('should have 2 parameters', function () { + expect(CollectionResponse).to.have.lengthOf(2); + }); + + it('should create a new instance of the CollectionResponse class', function () { + expect(() => new CollectionResponse(200, [1, 2, 3])).to.not.throw(); + }); + + it('should have a property named count', function () { + expect(new CollectionResponse(200, [1, 2, 3])).to.have.property('count'); + }); + + it('should have a property named items', function () { + expect(new CollectionResponse(200, [1, 2, 3])).to.have.property('items'); + }); + + it('should set the count property to the value passed to the constructor', function () { + expect(new CollectionResponse(200, [1, 2, 3]).count).to.equal(200); + }); + + it('should set the items property to the value passed to the constructor', function () { + expect(new CollectionResponse(200, [1, 2, 3]).items).to.deep.equal([ + 1, 2, 3, + ]); + }); +});