feat: added save record request model with tests
This commit is contained in:
@@ -15,7 +15,7 @@ export class GetRecordsByAppIdRequest {
|
|||||||
/**
|
/**
|
||||||
* @property {DataFormat} dataFormat - The format of the data in the response.
|
* @property {DataFormat} dataFormat - The format of the data in the response.
|
||||||
*/
|
*/
|
||||||
public dataFormat: DataFormat;
|
public dataFormat: DataFormat = DataFormat.Raw;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @property {PagingRequest} pagingRequest - The paging request.
|
* @property {PagingRequest} pagingRequest - The paging request.
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ export class Record {
|
|||||||
* @param {RecordValue[]} fieldData - The data for the fields in the record.
|
* @param {RecordValue[]} fieldData - The data for the fields in the record.
|
||||||
* @returns {Record} - A new instance of Record.
|
* @returns {Record} - A new instance of Record.
|
||||||
*/
|
*/
|
||||||
constructor(appId: number, recordId: number, fieldData: RecordValue[]) {
|
constructor(appId: number, recordId: number, fieldData: RecordValue[] = []) {
|
||||||
this.appId = appId;
|
this.appId = appId;
|
||||||
this.recordId = recordId;
|
this.recordId = recordId;
|
||||||
this.fieldData = fieldData;
|
this.fieldData = fieldData;
|
||||||
|
|||||||
@@ -0,0 +1,28 @@
|
|||||||
|
export class SaveRecordRequest {
|
||||||
|
/**
|
||||||
|
* @property {number} appId - The id of the app that the record belongs to.
|
||||||
|
*/
|
||||||
|
public appId: number;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @property {number} recordId - The id of the record.
|
||||||
|
* @remarks If the record id is not provided a new record will be created. Otherwise, the existing record will be updated.
|
||||||
|
*/
|
||||||
|
public recordId: number | null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @property {Map<number, any>} fields - The data for the fields in the record.
|
||||||
|
* @remarks The key is the field id and the value is the value for the field.
|
||||||
|
*/
|
||||||
|
public fields: Map<number, any>;
|
||||||
|
|
||||||
|
constructor(
|
||||||
|
appId: number,
|
||||||
|
recordId: number | null = null,
|
||||||
|
fields: Map<number, any> = new Map<number, any>()
|
||||||
|
) {
|
||||||
|
this.appId = appId;
|
||||||
|
this.recordId = recordId;
|
||||||
|
this.fields = fields;
|
||||||
|
}
|
||||||
|
}
|
||||||
+12
-2
@@ -12,8 +12,8 @@ describe('Record', function () {
|
|||||||
expect(Record).to.have.property('constructor');
|
expect(Record).to.have.property('constructor');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should have a constructor that has 3 parameters', function () {
|
it('should have a constructor that has 2 parameters', function () {
|
||||||
expect(Record).to.have.lengthOf(3);
|
expect(Record).to.have.lengthOf(2);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should have a constructor that sets its properties correctly', function () {
|
it('should have a constructor that sets its properties correctly', function () {
|
||||||
@@ -29,6 +29,16 @@ describe('Record', function () {
|
|||||||
.with.lengthOf(2);
|
.with.lengthOf(2);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should have a constructor that sets its properties correctly when no fieldData is provided', function () {
|
||||||
|
const record = new Record(1, 2);
|
||||||
|
expect(record).to.have.property('appId', 1);
|
||||||
|
expect(record).to.have.property('recordId', 2);
|
||||||
|
expect(record)
|
||||||
|
.to.have.property('fieldData')
|
||||||
|
.that.is.an('array')
|
||||||
|
.with.lengthOf(0);
|
||||||
|
});
|
||||||
|
|
||||||
it('should have an appId property', function () {
|
it('should have an appId property', function () {
|
||||||
expect(
|
expect(
|
||||||
new Record(1, 2, [
|
new Record(1, 2, [
|
||||||
|
|||||||
@@ -0,0 +1,57 @@
|
|||||||
|
import { SaveRecordRequest } from '../src/models/SaveRecordRequest';
|
||||||
|
import { expect } from 'chai';
|
||||||
|
|
||||||
|
describe('SaveRecordRequest', function () {
|
||||||
|
it('should be defined', function () {
|
||||||
|
expect(SaveRecordRequest).to.not.be.undefined;
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should have a constructor', function () {
|
||||||
|
expect(SaveRecordRequest).to.have.property('constructor');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should have a constructor that takes 1 parameter', function () {
|
||||||
|
expect(SaveRecordRequest.constructor).to.have.lengthOf(1);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should have an appId property', function () {
|
||||||
|
expect(new SaveRecordRequest(1)).to.have.property('appId');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should have a recordId property', function () {
|
||||||
|
expect(new SaveRecordRequest(1)).to.have.property('recordId');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should have a fields property', function () {
|
||||||
|
expect(new SaveRecordRequest(1)).to.have.property('fields');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should have a constructor that sets its properties correctly', function () {
|
||||||
|
const saveRecordRequest = new SaveRecordRequest(1);
|
||||||
|
expect(saveRecordRequest.appId).to.equal(1);
|
||||||
|
expect(saveRecordRequest.recordId).to.be.null;
|
||||||
|
expect(saveRecordRequest.fields).to.not.be.null.and.not.be.undefined;
|
||||||
|
expect(saveRecordRequest.fields).to.have.lengthOf(0);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should have a constructor that sets its properties correctly when passed a recordId', function () {
|
||||||
|
const saveRecordRequest = new SaveRecordRequest(1, 2);
|
||||||
|
expect(saveRecordRequest.appId).to.equal(1);
|
||||||
|
expect(saveRecordRequest.recordId).to.equal(2);
|
||||||
|
expect(saveRecordRequest.fields).to.not.be.null.and.not.be.undefined;
|
||||||
|
expect(saveRecordRequest.fields).to.have.lengthOf(0);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should have a constructor that sets its properties correctly when passed a recordId and fields', function () {
|
||||||
|
const map = new Map([
|
||||||
|
[1, 'test'],
|
||||||
|
[2, 'test'],
|
||||||
|
]);
|
||||||
|
const saveRecordRequest = new SaveRecordRequest(1, 2, map);
|
||||||
|
expect(saveRecordRequest).to.have.property('appId', 1);
|
||||||
|
expect(saveRecordRequest).to.have.property('recordId', 2);
|
||||||
|
expect(saveRecordRequest).to.have.property('fields', map);
|
||||||
|
expect(saveRecordRequest.fields).to.not.be.null.and.not.be.undefined;
|
||||||
|
expect(saveRecordRequest.fields).to.have.lengthOf(2);
|
||||||
|
});
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user