diff --git a/src/enums/RecordValueType.ts b/src/enums/RecordValueType.ts new file mode 100644 index 0000000..0f6ef19 --- /dev/null +++ b/src/enums/RecordValueType.ts @@ -0,0 +1,75 @@ +/** + * @enum RecordValueType - The type of the record value. + */ +export enum RecordValueType { + /** + * @constant String - The record value is a string. + * @type {string} + */ + String = 'String', + + /** + * @constant Integer - The record value is an integer. + * @type {string} + */ + Integer = 'Integer', + + /** + * @constant Decimal - The record value is a decimal. + * @type {string} + */ + Decimal = 'Decimal', + + /** + * @constant Date - The record value is a Date. + * @type {string} + */ + Date = 'Date', + + /** + * @constant TimeSpan - The record value is a TimeSpan. + * @type {string} + */ + TimeSpan = 'TimeSpan', + + /** + * @constant Guid - The record value is a Guid. + */ + Guid = 'Guid', + + /** + * @constant StringList - The record value is a list of strings. + * @type {string} + */ + StringList = 'StringList', + + /** + * @constant IntegerList - The record value is a list of integers. + * @type {string} + */ + IntegerList = 'IntegerList', + + /** + * @constant GuidList - The record value is a list of Guids. + * @type {string} + */ + GuidList = 'GuidList', + + /** + * @constant AttachmentList - The record value is a list of attachments. + * @type {string} + */ + AttachmentList = 'AttachmentList', + + /** + * @constant ScoringGroupList - The record value is a list of scoring groups. + * @type {string} + */ + ScoringGroupList = 'ScoringGroupList', + + /** + * @constant FileList - The record value is a list of files. + * @type {string} + */ + FileList = 'FileList', +} diff --git a/src/enums/ResultValueType.ts b/src/enums/ResultValueType.ts deleted file mode 100644 index 5361dd3..0000000 --- a/src/enums/ResultValueType.ts +++ /dev/null @@ -1,75 +0,0 @@ -/** - * @enum ResultValueType - The type of the result value. - */ -export enum ResultValueType { - /** - * @constant String - The result value is a string. - * @type {string} - */ - String = 'String', - - /** - * @constant Integer - The result value is an integer. - * @type {string} - */ - Integer = 'Integer', - - /** - * @constant Decimal - The result value is a decimal. - * @type {string} - */ - Decimal = 'Decimal', - - /** - * @constant Date - The result value is a Date. - * @type {string} - */ - Date = 'Date', - - /** - * @constant TimeSpan - The result value is a TimeSpan. - * @type {string} - */ - TimeSpan = 'TimeSpan', - - /** - * @constant Guid - The result value is a Guid. - */ - Guid = 'Guid', - - /** - * @constant StringList - The result value is a list of strings. - * @type {string} - */ - StringList = 'StringList', - - /** - * @constant IntegerList - The result value is a list of integers. - * @type {string} - */ - IntegerList = 'IntegerList', - - /** - * @constant GuidList - The result value is a list of Guids. - * @type {string} - */ - GuidList = 'GuidList', - - /** - * @constant AttachmentList - The result value is a list of attachments. - * @type {string} - */ - AttachmentList = 'AttachmentList', - - /** - * @constant ScoringGroupList - The result value is a list of scoring groups. - * @type {string} - */ - ScoringGroupList = 'ScoringGroupList', - - /** - * @constant FileList - The result value is a list of files. - * @type {string} - */ - FileList = 'FileList', -} diff --git a/src/models/ApiResponse.ts b/src/models/ApiResponse.ts index 0aa6ded..ecdbb2b 100644 --- a/src/models/ApiResponse.ts +++ b/src/models/ApiResponse.ts @@ -1,5 +1,8 @@ import { type AxiosResponse } from 'axios'; +import { FieldStatus } from '../enums/FieldStatus'; import { FieldType } from '../enums/FieldType'; +import { FormulaOutputType } from '../enums/FormulaOutputType'; +import { Multiplicity } from '../enums/Multiplicity'; import { App } from './App'; import { CollectionResponse } from './CollectionResponse'; import { CreatedWithIdResponse } from './CreatedWithIdResponse'; @@ -327,48 +330,55 @@ export class ApiResponse { * @returns {Field} - The converted field object. */ private static getFieldByType(fieldItem: any): Field { - switch (fieldItem.type) { + const type = FieldType[fieldItem.type]; + const status = FieldStatus[fieldItem.status]; + + switch (type) { case FieldType.Reference: { + const multiplicity = Multiplicity[fieldItem.multiplicity]; + return new ReferenceField( fieldItem.id, fieldItem.appId, fieldItem.name, - fieldItem.type, - fieldItem.status, + type, + status, fieldItem.isRequired, fieldItem.isUnique, - fieldItem.multiplicity, + multiplicity, fieldItem.referencedAppId ); } case FieldType.List: { const values = ApiResponse.getListValues(fieldItem); + const multiplicity = Multiplicity[fieldItem.multiplicity]; return new ListField( fieldItem.id, fieldItem.appId, fieldItem.name, - fieldItem.type, - fieldItem.status, + type, + status, fieldItem.isRequired, fieldItem.isUnique, - fieldItem.multiplicity, + multiplicity, fieldItem.listId, values ); } case FieldType.Formula: { const values = ApiResponse.getListValues(fieldItem); + const outputType = FormulaOutputType[fieldItem.outputType]; return new FormulaField( fieldItem.id, fieldItem.appId, fieldItem.name, - fieldItem.type, - fieldItem.status, + type, + status, fieldItem.isRequired, fieldItem.isUnique, - fieldItem.outputType, + outputType, values ); } @@ -377,8 +387,8 @@ export class ApiResponse { fieldItem.id, fieldItem.appId, fieldItem.name, - fieldItem.type, - fieldItem.status, + type, + status, fieldItem.isRequired, fieldItem.isUnique ); diff --git a/src/models/App.ts b/src/models/App.ts index 90e05cb..ca8ff98 100644 --- a/src/models/App.ts +++ b/src/models/App.ts @@ -5,17 +5,17 @@ export class App { /** * @property {string} href - The URL to the app */ - href: string; + public href: string; /** * @property {number} id - The id of the app */ - id: number; + public id: number; /** * @property {string} name - The name of the app */ - name: string; + public name: string; /** * @constructor - Creates a new instance of the App class. diff --git a/src/models/Attachment.ts b/src/models/Attachment.ts new file mode 100644 index 0000000..a84ad34 --- /dev/null +++ b/src/models/Attachment.ts @@ -0,0 +1,18 @@ +export class Attachment { + public fileId: number; + public fileName: string; + public notes: string; + public storageLocation: string; + + constructor( + fileId: number, + fileName: string, + notes: string, + storageLocation: string + ) { + this.fileId = fileId; + this.fileName = fileName; + this.notes = notes; + this.storageLocation = storageLocation; + } +} diff --git a/src/models/Field.ts b/src/models/Field.ts index fc57bf3..51afe04 100644 --- a/src/models/Field.ts +++ b/src/models/Field.ts @@ -1,5 +1,5 @@ -import { FieldStatus } from '../enums/FieldStatus'; -import { FieldType } from '../enums/FieldType'; +import { type FieldStatus } from '../enums/FieldStatus'; +import { type FieldType } from '../enums/FieldType'; /** * @class Field - Represents a Field. @@ -45,36 +45,26 @@ export class Field { * @param {number} id - The id of the Field. * @param {number} appId - The id of the App that the Field belongs to. * @param {string} name - The name of the Field. - * @param {string} type - The type of the Field. - * @param {string} status - The status of the Field. + * @param {FieldType} type - The type of the Field. + * @param {FieldStatus} status - The status of the Field. * @param {boolean} isRequired - Indicates whether or not the Field is required. * @param {boolean} isUnique - Indicates whether or not the Field is required to be unique. * @returns {Field} - A new Field. - * @throws {Error} - Throws an error if the type is not valid. - * @throws {Error} - Throws an error if the status is not valid. */ public constructor( id: number, appId: number, name: string, - type: string, - status: string, + type: FieldType, + status: FieldStatus, isRequired: boolean, isUnique: boolean ) { - if (FieldType[type] === undefined) { - throw new Error(`The type '${type}' is not a valid FieldType.`); - } - - if (FieldStatus[status] === undefined) { - throw new Error(`The status '${status}' is not a valid FieldStatus.`); - } - this.id = id; this.appId = appId; this.name = name; - this.type = FieldType[type]; - this.status = FieldStatus[status]; + this.type = type; + this.status = status; this.isRequired = isRequired; this.isUnique = isUnique; } diff --git a/src/models/FormulaField.ts b/src/models/FormulaField.ts index 8865171..442adc6 100644 --- a/src/models/FormulaField.ts +++ b/src/models/FormulaField.ts @@ -1,4 +1,6 @@ -import { FormulaOutputType } from '../enums/FormulaOutputType'; +import { type FieldStatus } from '../enums/FieldStatus'; +import { type FieldType } from '../enums/FieldType'; +import { type FormulaOutputType } from '../enums/FormulaOutputType'; import { Field } from './Field'; import { type ListValue } from './ListValue'; @@ -21,35 +23,27 @@ export class FormulaField extends Field { * @param {number} id - The id of the formula field. * @param {number} appId - The id of the app the formula field belongs to. * @param {string} name - The name of the formula field. - * @param {string} type - The type of the formula field. - * @param {string} status - The status of the formula field. + * @param {FieldType} type - The type of the formula field. + * @param {FieldStatus} status - The status of the formula field. * @param {boolean} isRequired - Whether the formula field is required. * @param {boolean} isUnique - Whether the formula field is unique. - * @param {string} outputType - The output type of the formula field. + * @param {FormulaOutputType} outputType - The output type of the formula field. * @param {ListValue[]} values - The list values of the formula field. * @returns {FormulaField} - A new FormulaField. - * @throws {Error} - Throws an error if the outputType is not a valid FormulaOutputType. */ constructor( id: number, appId: number, name: string, - type: string, - status: string, + type: FieldType, + status: FieldStatus, isRequired: boolean, isUnique: boolean, - outputType: string, + outputType: FormulaOutputType, values: ListValue[] ) { super(id, appId, name, type, status, isRequired, isUnique); - - if (FormulaOutputType[outputType] === undefined) { - throw new Error( - `The outputType ${outputType} is not a valid FormulaOutputType.` - ); - } - - this.outputType = FormulaOutputType[outputType]; + this.outputType = outputType; this.values = values; } } diff --git a/src/models/ListField.ts b/src/models/ListField.ts index e4c280b..5e92cdc 100644 --- a/src/models/ListField.ts +++ b/src/models/ListField.ts @@ -1,4 +1,6 @@ -import { Multiplicity } from '../enums/Multiplicity'; +import { type FieldStatus } from '../enums/FieldStatus'; +import { type FieldType } from '../enums/FieldType'; +import { type Multiplicity } from '../enums/Multiplicity'; import { Field } from './Field'; import { type ListValue } from './ListValue'; @@ -26,37 +28,29 @@ export class ListField extends Field { * @param {number} id - The id of the list field. * @param {number} appId - The id of the app the list field belongs to. * @param {string} name - The name of the list field. - * @param {string} type - The type of the list field. - * @param {string} status - The status of the list field. + * @param {FieldType} type - The type of the list field. + * @param {FieldStatus} status - The status of the list field. * @param {boolean} isRequired - Whether the list field is required. * @param {boolean} isUnique - Whether the list field is unique. - * @param {string} multiplicity - The multiplicity of the list field. + * @param {Multiplicity} multiplicity - The multiplicity of the list field. * @param {number} listId - The id of the list the list field belongs to. * @param {ListValue[]} values - The list values of the list field. * @returns {ListField} - A new ListField. - * @throws {Error} - Throws an error if the multiplicity is not a valid Multiplicity. */ constructor( id: number, appId: number, name: string, - type: string, - status: string, + type: FieldType, + status: FieldStatus, isRequired: boolean, isUnique: boolean, - multiplicity: string, + multiplicity: Multiplicity, listId: number, values: ListValue[] ) { super(id, appId, name, type, status, isRequired, isUnique); - - if (Multiplicity[multiplicity] === undefined) { - throw new Error( - `The multiplicity ${multiplicity} is not a valid Multiplicity.` - ); - } - - this.multiplicity = Multiplicity[multiplicity]; + this.multiplicity = multiplicity; this.listId = listId; this.values = values; } diff --git a/src/models/ListValue.ts b/src/models/ListValue.ts index 9fc8442..29032a3 100644 --- a/src/models/ListValue.ts +++ b/src/models/ListValue.ts @@ -23,7 +23,7 @@ export class ListValue { public numericValue: number; /** - * + * @property {string} color - The color of the list value. */ public color: string; diff --git a/src/models/PagingRequest.ts b/src/models/PagingRequest.ts index ed44410..532a0c5 100644 --- a/src/models/PagingRequest.ts +++ b/src/models/PagingRequest.ts @@ -7,12 +7,12 @@ export class PagingRequest { /** * @property {number} pageNumber - The page number of the request. */ - pageNumber: number; + public pageNumber: number; /** * @property {number} pageSize - The page size of the request. */ - pageSize: number; + public pageSize: number; /** * @constructor - Creates a new instance of the PagingRequest class. diff --git a/src/models/Record.ts b/src/models/Record.ts new file mode 100644 index 0000000..a92b2bc --- /dev/null +++ b/src/models/Record.ts @@ -0,0 +1,38 @@ +import { type RecordValue } from './RecordValue'; + +/** + * @class Record - A record in an app. + */ +export class Record { + /** + * @property {number} appId - The id of the app that the record belongs to. + */ + public appId: number; + + /** + * @property {number} recordId - The id of the record. + */ + public recordId: number; + + /** + * @property {Array>} fieldData - The data for the fields in the record. + */ + public fieldData: Array>; + + /** + * @constructor - Creates a new instance of Record. + * @param {number} appId - The id of the app that the record belongs to. + * @param {number} recordId - The id of the record. + * @param {Array>} fieldData - The data for the fields in the record. + * @returns {Record} - A new instance of Record. + */ + constructor( + appId: number, + recordId: number, + fieldData: Array> + ) { + this.appId = appId; + this.recordId = recordId; + this.fieldData = fieldData; + } +} diff --git a/src/models/RecordValue.ts b/src/models/RecordValue.ts new file mode 100644 index 0000000..27ee5ee --- /dev/null +++ b/src/models/RecordValue.ts @@ -0,0 +1,34 @@ +import { type RecordValueType } from '../enums/RecordValueType'; + +/** + * @class RecordValue - A value for a field in a record. + */ +export class RecordValue { + /** + * @property {RecordValueType} type - The type of the record value. + */ + public type: RecordValueType; + + /** + * @property {number} fieldId - The id of the field. + */ + public fieldId: number; + + /** + * @property {T} value - The value of the field. + */ + public value: T; + + /** + * @constructor - Creates a new instance of RecordValue. + * @param {RecordValueType} type - The type of the record value. + * @param {number} fieldId - The id of the field. + * @param {T} value - The value of the field. + * @returns {RecordValue} - A new instance of RecordValue. + */ + constructor(type: RecordValueType, fieldId: number, value: T) { + this.type = type; + this.fieldId = fieldId; + this.value = value; + } +} diff --git a/src/models/ReferenceField.ts b/src/models/ReferenceField.ts index e1646dc..bc92985 100644 --- a/src/models/ReferenceField.ts +++ b/src/models/ReferenceField.ts @@ -1,4 +1,6 @@ -import { Multiplicity } from '../enums/Multiplicity'; +import { type FieldStatus } from '../enums/FieldStatus'; +import { type FieldType } from '../enums/FieldType'; +import { type Multiplicity } from '../enums/Multiplicity'; import { Field } from './Field'; /** @@ -20,35 +22,27 @@ export class ReferenceField extends Field { * @param {number} id - The id of the reference field. * @param {number} appId - The id of the app the reference field belongs to. * @param {string} name - The name of the reference field. - * @param {string} type - The type of the reference field. - * @param {string} status - The status of the reference field. + * @param {FieldType} type - The type of the reference field. + * @param {FieldStatus} status - The status of the reference field. * @param {boolean} isRequired - Whether the reference field is required. * @param {boolean} isUnique - Whether the reference field is unique. - * @param {string} multiplicity - The multiplicity of the reference field. + * @param {Multiplicity} multiplicity - The multiplicity of the reference field. * @param {number} referencedAppId - The id of the app the reference field references. * @returns {ReferenceField} - A new ReferenceField. - * @throws {Error} - Throws an error if the multiplicity is not a valid Multiplicity.jjkdleroritlasaxmvjd */ constructor( id: number, appId: number, name: string, - type: string, - status: string, + type: FieldType, + status: FieldStatus, isRequired: boolean, isUnique: boolean, - multiplicity: string, + multiplicity: Multiplicity, referencedAppId: number ) { super(id, appId, name, type, status, isRequired, isUnique); - - if (Multiplicity[multiplicity] === undefined) { - throw new Error( - `The multiplicity ${multiplicity} is not a valid Multiplicity.` - ); - } - - this.multiplicity = Multiplicity[multiplicity]; + this.multiplicity = multiplicity; this.referencedAppId = referencedAppId; } } diff --git a/src/models/Row.ts b/src/models/Row.ts index 80c9c08..dd5e5ef 100644 --- a/src/models/Row.ts +++ b/src/models/Row.ts @@ -1,8 +1,24 @@ +/** + * @class Row - Represents a row of data in a report. + */ export class Row { + /** + * @property {number} recordId - The id of the record that the row represents. + */ public recordId: number; - public cells: object[]; - constructor(recordId: number, cells: object[]) { + /** + * @property {any[]} cells - The cells in the row. + */ + public cells: any[]; + + /** + * @constructor - Creates a new instance of Row. + * @param {number} recordId - The id of the record that the row represents. + * @param {any[]} cells - The cells in the row. + * @returns {Row} - A new instance of Row. + */ + constructor(recordId: number, cells: any[]) { this.recordId = recordId; this.cells = cells; } diff --git a/src/models/ScoringGroup.ts b/src/models/ScoringGroup.ts new file mode 100644 index 0000000..37ad515 --- /dev/null +++ b/src/models/ScoringGroup.ts @@ -0,0 +1,44 @@ +/** + * @class ScoringGroup - A class that represents a scoring group. + */ +export class ScoringGroup { + /** + * @property {string} listValueId - The id of the list value. + */ + public listValueId: string; + + /** + * @property {string} name - The name of the scoring group. + */ + public name: string; + + /** + * @property {number} score - The score of the scoring group. + */ + public score: number; + + /** + * @property {number} maximumScore - The maximum score of the scoring group. + */ + public maximumScore: number; + + /** + * @constructor - Creates a new instance of ScoringGroup. + * @param {string} listValueId - The id of the list value. + * @param {string} name - The name of the scoring group. + * @param {number} score - The score of the scoring group. + * @param {number} maximumScore - The maximum score of the scoring group. + * @returns {ScoringGroup} - A new instance of ScoringGroup. + */ + constructor( + listValueId: string, + name: string, + score: number, + maximumScore: number + ) { + this.listValueId = listValueId; + this.name = name; + this.score = score; + this.maximumScore = maximumScore; + } +} diff --git a/src/models/TimeSpanData.ts b/src/models/TimeSpanData.ts new file mode 100644 index 0000000..327fc9d --- /dev/null +++ b/src/models/TimeSpanData.ts @@ -0,0 +1,49 @@ +import { type TimeSpanIncrement } from '../enums/TimeSpanIncrement'; +import { type TimeSpanRecurrenceType } from '../enums/TimeSpanRecurrenceType'; + +export class TimeSpanData { + /** + * @property {number} quantity - The quantity of the time span. + */ + public quantity: number; + + /** + * @property {TimeSpanIncrement} increment - The increment of the time span. + */ + public increment: TimeSpanIncrement; + + /** + * @property {TimeSpanRecurrence} recurrence - The recurrence of the time span. + */ + public recurrence: TimeSpanRecurrenceType; + + /** + * @property {number} endAfterOccurrences - The number of occurrences of the time span. + */ + public endAfterOccurrences: number; + + public endByDate: Date; + + /** + * @constructor - Creates a new instance of TimeSpanData. + * @param {number} quantity - The quantity of the time span. + * @param {TimeSpanIncrement} increment - The increment of the time span. + * @param {TimeSpanRecurrenceType} recurrence - The recurrence of the time span. + * @param {number} endAfterOccurrences - The number of occurrences of the time span. + * @param {Date} endByDate - The end date of the time span. + * @returns {TimeSpanData} - A new instance of TimeSpanData. + */ + constructor( + quantity: number, + increment: TimeSpanIncrement, + recurrence: TimeSpanRecurrenceType, + endAfterOccurrences: number, + endByDate: Date + ) { + this.quantity = quantity; + this.increment = increment; + this.recurrence = recurrence; + this.endAfterOccurrences = endAfterOccurrences; + this.endByDate = endByDate; + } +} diff --git a/tests/Attachment.spec.ts b/tests/Attachment.spec.ts new file mode 100644 index 0000000..205a616 --- /dev/null +++ b/tests/Attachment.spec.ts @@ -0,0 +1,6 @@ +import { Attachment } from '../src/models/Attachment'; +import { expect } from 'chai'; + +describe('Attachment', function () { + throw new Error('Not implemented'); +}); diff --git a/tests/Field.spec.ts b/tests/Field.spec.ts index b45c110..9dbd5e0 100644 --- a/tests/Field.spec.ts +++ b/tests/Field.spec.ts @@ -1,4 +1,6 @@ import { expect } from 'chai'; +import { FieldStatus } from '../src/enums/FieldStatus'; +import { FieldType } from '../src/enums/FieldType'; import { Field } from '../src/models/Field'; describe('Field', function () { @@ -16,38 +18,36 @@ describe('Field', function () { it('should create a new instance of the Field class', function () { expect( - () => new Field(1, 1, 'Text Field', 'Text', 'Enabled', true, false) + () => + new Field( + 1, + 1, + 'Text Field', + FieldType.Text, + FieldStatus.Enabled, + true, + false + ) ).to.not.throw(); }); - it('should throw an error when the type parameter is not a valid value', function () { - expect( - () => new Field(1, 1, 'Text Field', 'Invalid', 'Enabled', true, false) - ).to.throw(); - }); - - it('should throw an error when the status parameter is not a valid value', function () { - expect( - () => new Field(1, 1, 'Text Field', 'Text', 'Unabled', true, false) - ).to.throw(); - }); - it('should create a new instance of the Field class with the correct properties and values', function () { - const field = new Field(1, 1, 'Text Field', 'Text', 'Enabled', true, false); + const field = new Field( + 1, + 1, + 'Text Field', + FieldType.Text, + FieldStatus.Enabled, + true, + false + ); - expect(field).to.have.property('id'); - expect(field).to.have.property('appId'); - expect(field).to.have.property('name'); - expect(field).to.have.property('type'); - expect(field).to.have.property('status'); - expect(field).to.have.property('isRequired'); - expect(field).to.have.property('isUnique'); - expect(field.id).to.equal(1); - expect(field.appId).to.equal(1); - expect(field.name).to.equal('Text Field'); - expect(field.type).to.equal('Text'); - expect(field.status).to.equal('Enabled'); - expect(field.isRequired).to.equal(true); - expect(field.isUnique).to.equal(false); + expect(field).to.have.property('id', 1); + expect(field).to.have.property('appId', 1); + expect(field).to.have.property('name', 'Text Field'); + expect(field).to.have.property('type', FieldType.Text); + expect(field).to.have.property('status', FieldStatus.Enabled); + expect(field).to.have.property('isRequired', true); + expect(field).to.have.property('isUnique', false); }); }); diff --git a/tests/FormulaField.spec.ts b/tests/FormulaField.spec.ts index 47e2f57..0aa26ec 100644 --- a/tests/FormulaField.spec.ts +++ b/tests/FormulaField.spec.ts @@ -1,5 +1,8 @@ import { FormulaField } from '../src/models/FormulaField'; import { expect } from 'chai'; +import { FieldType } from '../src/enums/FieldType'; +import { FieldStatus } from '../src/enums/FieldStatus'; +import { FormulaOutputType } from '../src/enums/FormulaOutputType'; describe('FormulaField', function () { it('should be defined', function () { @@ -14,33 +17,16 @@ describe('FormulaField', function () { expect(FormulaField).to.have.property('constructor'); }); - it('should throw an error if the outputType is not a valid FormulaOutputType', function () { - expect( - () => - new FormulaField( - 1, - 1, - 'Formula Field', - 'Formula', - 'Enabled', - false, - false, - 'NotAType', - [] - ) - ).to.throw(); - }); - it('should create a new FormulaField', function () { const formulaField = new FormulaField( 1, 1, 'Formula Field', - 'Formula', - 'Enabled', + FieldType.Formula, + FieldStatus.Enabled, false, false, - 'Text', + FormulaOutputType.Text, [] ); expect(formulaField).to.be.an.instanceOf(FormulaField); @@ -51,11 +37,11 @@ describe('FormulaField', function () { 1, 1, 'Formula Field', - 'Formula', - 'Enabled', + FieldType.Formula, + FieldStatus.Enabled, false, false, - 'Text', + FormulaOutputType.Text, [] ); expect(formulaField).to.have.property('outputType'); @@ -66,11 +52,11 @@ describe('FormulaField', function () { 1, 1, 'Formula Field', - 'Formula', - 'Enabled', + FieldType.Formula, + FieldStatus.Enabled, false, false, - 'Text', + FormulaOutputType.Text, [] ); expect(formulaField).to.have.property('values'); diff --git a/tests/GetPagedFieldsResponse.spec.ts b/tests/GetPagedFieldsResponse.spec.ts index 09d67c7..cb4f941 100644 --- a/tests/GetPagedFieldsResponse.spec.ts +++ b/tests/GetPagedFieldsResponse.spec.ts @@ -1,6 +1,8 @@ import { GetPagedFieldsResponse } from '../src/models/GetPagedFieldsResponse'; import { Field } from '../src/models/Field'; import { expect } from 'chai'; +import { FieldType } from '../src/enums/FieldType'; +import { FieldStatus } from '../src/enums/FieldStatus'; describe('GetPagedFieldsResponse', function () { it('should be defined', function () { @@ -17,7 +19,17 @@ describe('GetPagedFieldsResponse', function () { it('should construct a new instance of GetPagedFieldsResponse', function () { const getPagedFieldsResponse = new GetPagedFieldsResponse( - [new Field(1, 1, 'Text Field 1', 'Text', 'Enabled', false, false)], + [ + new Field( + 1, + 1, + 'Text Field 1', + FieldType.Text, + FieldStatus.Enabled, + false, + false + ), + ], 1, 10, 100, diff --git a/tests/ListField.spec.ts b/tests/ListField.spec.ts index ed2a725..b2e639f 100644 --- a/tests/ListField.spec.ts +++ b/tests/ListField.spec.ts @@ -1,5 +1,8 @@ import { ListField } from '../src/models/ListField'; import { expect } from 'chai'; +import { FieldType } from '../src/enums/FieldType'; +import { FieldStatus } from '../src/enums/FieldStatus'; +import { Multiplicity } from '../src/enums/Multiplicity'; describe('ListField', function () { it('should be defined', function () { @@ -14,34 +17,16 @@ describe('ListField', function () { expect(ListField).to.have.property('constructor'); }); - it('should throw an error if the multiplicity is not valid', function () { - expect( - () => - new ListField( - 1, - 1, - 'List Field', - 'List', - 'Enabled', - false, - false, - 'Alone', - 1, - [] - ) - ).to.throw(); - }); - it('should create a new ListField', function () { const listField = new ListField( 1, 1, 'List Field', - 'List', - 'Enabled', + FieldType.List, + FieldStatus.Enabled, false, false, - 'SingleSelect', + Multiplicity.SingleSelect, 1, [] ); @@ -53,11 +38,11 @@ describe('ListField', function () { 1, 1, 'List Field', - 'List', - 'Enabled', + FieldType.List, + FieldStatus.Enabled, false, false, - 'SingleSelect', + Multiplicity.SingleSelect, 1, [] ); @@ -69,11 +54,11 @@ describe('ListField', function () { 1, 1, 'List Field', - 'List', - 'Enabled', + FieldType.List, + FieldStatus.Enabled, false, false, - 'SingleSelect', + Multiplicity.SingleSelect, 1, [] ); @@ -85,11 +70,11 @@ describe('ListField', function () { 1, 1, 'List Field', - 'List', - 'Enabled', + FieldType.List, + FieldStatus.Enabled, false, false, - 'SingleSelect', + Multiplicity.SingleSelect, 1, [] ); diff --git a/tests/Record.spec.ts b/tests/Record.spec.ts new file mode 100644 index 0000000..37844b3 --- /dev/null +++ b/tests/Record.spec.ts @@ -0,0 +1,89 @@ +import { Record } from '../src/models/Record'; +import { expect } from 'chai'; +import { RecordValueType } from '../src/enums/RecordValueType'; + +describe('Record', function () { + it('should be defined', function () { + expect(Record).to.not.be.undefined; + }); + + it('should have a constructor', function () { + expect(Record).to.have.property('constructor'); + }); + + it('should have a constructor that has 3 parameters', function () { + expect(Record).to.have.lengthOf(3); + }); + + it('should have a constructor that sets its properties correctly', function () { + const record = new Record(1, 2, [ + { + type: RecordValueType.String, + fieldId: 1, + value: 'test', + }, + { + type: RecordValueType.String, + fieldId: 2, + value: 'test', + }, + ]); + 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(2); + }); + + it('should have an appId property', function () { + expect( + new Record(1, 2, [ + { + type: RecordValueType.String, + fieldId: 1, + value: 'test', + }, + { + type: RecordValueType.String, + fieldId: 2, + value: 'test', + }, + ]) + ).to.have.property('appId'); + }); + + it('should have a recordId property', function () { + expect( + new Record(1, 2, [ + { + type: RecordValueType.String, + fieldId: 1, + value: 'test', + }, + { + type: RecordValueType.String, + fieldId: 2, + value: 'test', + }, + ]) + ).to.have.property('recordId'); + }); + + it('should have a fieldData property', function () { + expect( + new Record(1, 2, [ + { + type: RecordValueType.String, + fieldId: 1, + value: 'test', + }, + { + type: RecordValueType.String, + fieldId: 2, + value: 'test', + }, + ]) + ).to.have.property('fieldData'); + }); +}); diff --git a/tests/RecordValue.spec.ts b/tests/RecordValue.spec.ts new file mode 100644 index 0000000..f761866 --- /dev/null +++ b/tests/RecordValue.spec.ts @@ -0,0 +1,46 @@ +import { RecordValue } from '../src/models/RecordValue'; +import { expect } from 'chai'; +import { RecordValueType } from '../src/enums/RecordValueType'; + +describe('RecordValue', function () { + it('should be defined', function () { + expect(RecordValue).to.not.be.undefined; + }); + + it('should have a constructor', function () { + expect(RecordValue).to.have.property('constructor'); + }); + + it('should have a constructor that has 3 parameters', function () { + expect(RecordValue).to.have.lengthOf(3); + }); + + it('should have a constructor that sets its properties correctly', function () { + const recordValue = new RecordValue( + RecordValueType.Date, + 2, + new Date().toUTCString() + ); + expect(recordValue).to.have.property('type', RecordValueType.Date); + expect(recordValue).to.have.property('fieldId', 2); + expect(recordValue).to.have.property('value', new Date().toUTCString()); + }); + + it('should have a type property', function () { + expect( + new RecordValue(RecordValueType.Date, 2, new Date().toUTCString()) + ).to.have.property('type'); + }); + + it('should have a fieldId property', function () { + expect( + new RecordValue(RecordValueType.Date, 2, new Date().toUTCString()) + ).to.have.property('fieldId'); + }); + + it('should have a value property', function () { + expect( + new RecordValue(RecordValueType.Date, 2, new Date().toUTCString()) + ).to.have.property('value'); + }); +}); diff --git a/tests/ResultValueType.spec.ts b/tests/RecordValueType.spec.ts similarity index 73% rename from tests/ResultValueType.spec.ts rename to tests/RecordValueType.spec.ts index cab8c7b..3b918aa 100644 --- a/tests/ResultValueType.spec.ts +++ b/tests/RecordValueType.spec.ts @@ -1,87 +1,87 @@ -import { ResultValueType } from '../src/enums/ResultValueType'; +import { RecordValueType } from '../src/enums/RecordValueType'; import { expect } from 'chai'; -describe('ResultValueType', function () { +describe('RecordValueType', function () { describe('String', function () { it('should return the correct value', function () { - const result = ResultValueType.String; + const result = RecordValueType.String; expect(result).to.equal('String'); }); }); describe('Integer', function () { it('should return the correct value', function () { - const result = ResultValueType.Integer; + const result = RecordValueType.Integer; expect(result).to.equal('Integer'); }); }); describe('Decimal', function () { it('should return the correct value', function () { - const result = ResultValueType.Decimal; + const result = RecordValueType.Decimal; expect(result).to.equal('Decimal'); }); }); describe('Date', function () { it('should return the correct value', function () { - const result = ResultValueType.Date; + const result = RecordValueType.Date; expect(result).to.equal('Date'); }); }); describe('TimeSpan', function () { it('should return the correct value', function () { - const result = ResultValueType.TimeSpan; + const result = RecordValueType.TimeSpan; expect(result).to.equal('TimeSpan'); }); }); describe('Guid', function () { it('should return the correct value', function () { - const result = ResultValueType.Guid; + const result = RecordValueType.Guid; expect(result).to.equal('Guid'); }); }); describe('StringList', function () { it('should return the correct value', function () { - const result = ResultValueType.StringList; + const result = RecordValueType.StringList; expect(result).to.equal('StringList'); }); }); describe('IntegerList', function () { it('should return the correct value', function () { - const result = ResultValueType.IntegerList; + const result = RecordValueType.IntegerList; expect(result).to.equal('IntegerList'); }); }); describe('GuidList', function () { it('should return the correct value', function () { - const result = ResultValueType.GuidList; + const result = RecordValueType.GuidList; expect(result).to.equal('GuidList'); }); }); describe('AttachmentList', function () { it('should return the correct value', function () { - const result = ResultValueType.AttachmentList; + const result = RecordValueType.AttachmentList; expect(result).to.equal('AttachmentList'); }); }); describe('ScoringGroupList', function () { it('should return the correct value', function () { - const result = ResultValueType.ScoringGroupList; + const result = RecordValueType.ScoringGroupList; expect(result).to.equal('ScoringGroupList'); }); }); describe('FileList', function () { it('should return the correct value', function () { - const result = ResultValueType.FileList; + const result = RecordValueType.FileList; expect(result).to.equal('FileList'); }); }); diff --git a/tests/ReferenceField.spec.ts b/tests/ReferenceField.spec.ts index 859d33b..eb47137 100644 --- a/tests/ReferenceField.spec.ts +++ b/tests/ReferenceField.spec.ts @@ -1,5 +1,8 @@ import { ReferenceField } from '../src/models/ReferenceField'; import { expect } from 'chai'; +import { FieldType } from '../src/enums/FieldType'; +import { FieldStatus } from '../src/enums/FieldStatus'; +import { Multiplicity } from '../src/enums/Multiplicity'; describe('ReferenceField', function () { it('should be defined', function () { @@ -14,33 +17,16 @@ describe('ReferenceField', function () { expect(ReferenceField).to.have.property('constructor'); }); - it('should throw an error if the multiplicity is not valid', function () { - expect( - () => - new ReferenceField( - 1, - 1, - 'Reference Field', - 'Reference', - 'Enabled', - false, - false, - 'Alone', - 1 - ) - ).to.throw(); - }); - it('should create a new ReferenceField', function () { const referenceField = new ReferenceField( 1, 1, 'Reference Field', - 'Reference', - 'Enabled', + FieldType.Reference, + FieldStatus.Enabled, false, false, - 'SingleSelect', + Multiplicity.SingleSelect, 1 ); expect(referenceField).to.be.an.instanceOf(ReferenceField); @@ -51,11 +37,11 @@ describe('ReferenceField', function () { 1, 1, 'Reference Field', - 'Reference', - 'Enabled', + FieldType.Reference, + FieldStatus.Enabled, false, false, - 'SingleSelect', + Multiplicity.SingleSelect, 1 ); expect(referenceField).to.have.property('multiplicity'); @@ -66,11 +52,11 @@ describe('ReferenceField', function () { 1, 1, 'Reference Field', - 'Reference', - 'Enabled', + FieldType.Reference, + FieldStatus.Enabled, false, false, - 'SingleSelect', + Multiplicity.SingleSelect, 1 ); expect(referenceField).to.have.property('referencedAppId'); diff --git a/tests/Report.spec.ts b/tests/Report.spec.ts index a94c8ab..6df6e82 100644 --- a/tests/Report.spec.ts +++ b/tests/Report.spec.ts @@ -27,4 +27,28 @@ describe('Report', function () { expect(report.name).to.be.equal('report'); expect(report.description).to.be.equal('report description'); }); + + it('should have an id property', function () { + expect(new Report(1, 1, 'report', 'report description')).to.have.property( + 'id' + ); + }); + + it('should have an appId property', function () { + expect(new Report(1, 1, 'report', 'report description')).to.have.property( + 'appId' + ); + }); + + it('should have a name property', function () { + expect(new Report(1, 1, 'report', 'report description')).to.have.property( + 'name' + ); + }); + + it('should have a description property', function () { + expect(new Report(1, 1, 'report', 'report description')).to.have.property( + 'description' + ); + }); }); diff --git a/tests/ReportData.spec.ts b/tests/ReportData.spec.ts index 97e157c..f2fb05a 100644 --- a/tests/ReportData.spec.ts +++ b/tests/ReportData.spec.ts @@ -47,4 +47,12 @@ describe('ReportData', function () { .with.lengthOf(2); }); }); + + it('should have a columns property', function () { + expect(new ReportData(['a', 'b'], [])).to.have.property('columns'); + }); + + it('should have a rows property', function () { + expect(new ReportData(['a', 'b'], [])).to.have.property('rows'); + }); }); diff --git a/tests/Row.spec.ts b/tests/Row.spec.ts index 58c7bc7..3f2a90e 100644 --- a/tests/Row.spec.ts +++ b/tests/Row.spec.ts @@ -16,4 +16,12 @@ describe('Row', function () { expect(row).to.have.property('recordId', 1); expect(row).to.have.property('cells').that.is.an('array').with.lengthOf(2); }); + + it('should have a recordId property', function () { + expect(new Row(1, [{}, {}])).to.have.property('recordId'); + }); + + it('should have a cells property', function () { + expect(new Row(1, [{}, {}])).to.have.property('cells'); + }); }); diff --git a/tests/ScoringGroup.spec.ts b/tests/ScoringGroup.spec.ts new file mode 100644 index 0000000..0106ec5 --- /dev/null +++ b/tests/ScoringGroup.spec.ts @@ -0,0 +1,6 @@ +import { ScoringGroup } from '../src/models/ScoringGroup'; +import { expect } from 'chai'; + +describe('ScoringGroup', function () { + throw new Error('Not implemented'); +}); diff --git a/tests/TimeSpanData.spec.ts b/tests/TimeSpanData.spec.ts new file mode 100644 index 0000000..61cd9a4 --- /dev/null +++ b/tests/TimeSpanData.spec.ts @@ -0,0 +1,6 @@ +import { TimeSpanData } from '../src/models/TimeSpanData'; +import { expect } from 'chai'; + +describe('TimeSpanData', function () { + throw new Error('Not implemented'); +});