Skip to content

Commit 3e78a35

Browse files
feat: add CollectionResponse model and tests
1 parent 2238e34 commit 3e78a35

File tree

2 files changed

+63
-0
lines changed

2 files changed

+63
-0
lines changed

src/models/CollectionResponse.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/**
2+
* @class CollectionResponse - A generic object for responses that contain collections of objects.
3+
*/
4+
export class CollectionResponse<T> {
5+
/**
6+
* @property {number} count - The total count of items in the collection.
7+
*/
8+
public count: number;
9+
10+
/**
11+
* @property {T} items - The items in the collection.
12+
*/
13+
public items: T;
14+
15+
/**
16+
* @constructor - Creates a new instance of the CollectionResponse class.
17+
* @param {number} count - The total count of items in the collection.
18+
* @param {T} items - The items in the collection.
19+
* @returns {CollectionResponse<T>} - A new instance of the CollectionResponse.
20+
*/
21+
constructor(count: number, items: T) {
22+
this.count = count;
23+
this.items = items;
24+
}
25+
}

tests/CollectionResponse.spec.ts

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import { expect } from 'chai';
2+
import { CollectionResponse } from '../src/models/CollectionResponse';
3+
4+
describe('CollectionResponse', function () {
5+
it('should be defined', function () {
6+
expect(CollectionResponse).to.not.be.undefined;
7+
});
8+
9+
it('should have a constructor', function () {
10+
expect(CollectionResponse).to.have.property('constructor');
11+
});
12+
13+
it('should have 2 parameters', function () {
14+
expect(CollectionResponse).to.have.lengthOf(2);
15+
});
16+
17+
it('should create a new instance of the CollectionResponse class', function () {
18+
expect(() => new CollectionResponse(200, [1, 2, 3])).to.not.throw();
19+
});
20+
21+
it('should have a property named count', function () {
22+
expect(new CollectionResponse(200, [1, 2, 3])).to.have.property('count');
23+
});
24+
25+
it('should have a property named items', function () {
26+
expect(new CollectionResponse(200, [1, 2, 3])).to.have.property('items');
27+
});
28+
29+
it('should set the count property to the value passed to the constructor', function () {
30+
expect(new CollectionResponse(200, [1, 2, 3]).count).to.equal(200);
31+
});
32+
33+
it('should set the items property to the value passed to the constructor', function () {
34+
expect(new CollectionResponse(200, [1, 2, 3]).items).to.deep.equal([
35+
1, 2, 3,
36+
]);
37+
});
38+
});

0 commit comments

Comments
 (0)