feat: begin working on implementing record methods

This commit is contained in:
StevanFreeborn
2023-02-09 22:21:20 -06:00
parent 3b3e210920
commit fde8b50717
30 changed files with 629 additions and 286 deletions
+75
View File
@@ -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',
}
-75
View File
@@ -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',
}
+22 -12
View File
@@ -1,5 +1,8 @@
import { type AxiosResponse } from 'axios'; import { type AxiosResponse } from 'axios';
import { FieldStatus } from '../enums/FieldStatus';
import { FieldType } from '../enums/FieldType'; import { FieldType } from '../enums/FieldType';
import { FormulaOutputType } from '../enums/FormulaOutputType';
import { Multiplicity } from '../enums/Multiplicity';
import { App } from './App'; import { App } from './App';
import { CollectionResponse } from './CollectionResponse'; import { CollectionResponse } from './CollectionResponse';
import { CreatedWithIdResponse } from './CreatedWithIdResponse'; import { CreatedWithIdResponse } from './CreatedWithIdResponse';
@@ -327,48 +330,55 @@ export class ApiResponse<T> {
* @returns {Field} - The converted field object. * @returns {Field} - The converted field object.
*/ */
private static getFieldByType(fieldItem: any): Field { private static getFieldByType(fieldItem: any): Field {
switch (fieldItem.type) { const type = FieldType[fieldItem.type];
const status = FieldStatus[fieldItem.status];
switch (type) {
case FieldType.Reference: { case FieldType.Reference: {
const multiplicity = Multiplicity[fieldItem.multiplicity];
return new ReferenceField( return new ReferenceField(
fieldItem.id, fieldItem.id,
fieldItem.appId, fieldItem.appId,
fieldItem.name, fieldItem.name,
fieldItem.type, type,
fieldItem.status, status,
fieldItem.isRequired, fieldItem.isRequired,
fieldItem.isUnique, fieldItem.isUnique,
fieldItem.multiplicity, multiplicity,
fieldItem.referencedAppId fieldItem.referencedAppId
); );
} }
case FieldType.List: { case FieldType.List: {
const values = ApiResponse.getListValues(fieldItem); const values = ApiResponse.getListValues(fieldItem);
const multiplicity = Multiplicity[fieldItem.multiplicity];
return new ListField( return new ListField(
fieldItem.id, fieldItem.id,
fieldItem.appId, fieldItem.appId,
fieldItem.name, fieldItem.name,
fieldItem.type, type,
fieldItem.status, status,
fieldItem.isRequired, fieldItem.isRequired,
fieldItem.isUnique, fieldItem.isUnique,
fieldItem.multiplicity, multiplicity,
fieldItem.listId, fieldItem.listId,
values values
); );
} }
case FieldType.Formula: { case FieldType.Formula: {
const values = ApiResponse.getListValues(fieldItem); const values = ApiResponse.getListValues(fieldItem);
const outputType = FormulaOutputType[fieldItem.outputType];
return new FormulaField( return new FormulaField(
fieldItem.id, fieldItem.id,
fieldItem.appId, fieldItem.appId,
fieldItem.name, fieldItem.name,
fieldItem.type, type,
fieldItem.status, status,
fieldItem.isRequired, fieldItem.isRequired,
fieldItem.isUnique, fieldItem.isUnique,
fieldItem.outputType, outputType,
values values
); );
} }
@@ -377,8 +387,8 @@ export class ApiResponse<T> {
fieldItem.id, fieldItem.id,
fieldItem.appId, fieldItem.appId,
fieldItem.name, fieldItem.name,
fieldItem.type, type,
fieldItem.status, status,
fieldItem.isRequired, fieldItem.isRequired,
fieldItem.isUnique fieldItem.isUnique
); );
+3 -3
View File
@@ -5,17 +5,17 @@ export class App {
/** /**
* @property {string} href - The URL to the app * @property {string} href - The URL to the app
*/ */
href: string; public href: string;
/** /**
* @property {number} id - The id of the app * @property {number} id - The id of the app
*/ */
id: number; public id: number;
/** /**
* @property {string} name - The name of the app * @property {string} name - The name of the app
*/ */
name: string; public name: string;
/** /**
* @constructor - Creates a new instance of the App class. * @constructor - Creates a new instance of the App class.
+18
View File
@@ -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;
}
}
+8 -18
View File
@@ -1,5 +1,5 @@
import { FieldStatus } from '../enums/FieldStatus'; import { type FieldStatus } from '../enums/FieldStatus';
import { FieldType } from '../enums/FieldType'; import { type FieldType } from '../enums/FieldType';
/** /**
* @class Field - Represents a Field. * @class Field - Represents a Field.
@@ -45,36 +45,26 @@ export class Field {
* @param {number} id - The id of the Field. * @param {number} id - The id of the Field.
* @param {number} appId - The id of the App that the Field belongs to. * @param {number} appId - The id of the App that the Field belongs to.
* @param {string} name - The name of the Field. * @param {string} name - The name of the Field.
* @param {string} type - The type of the Field. * @param {FieldType} type - The type of the Field.
* @param {string} status - The status of the Field. * @param {FieldStatus} status - The status of the Field.
* @param {boolean} isRequired - Indicates whether or not the Field is required. * @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. * @param {boolean} isUnique - Indicates whether or not the Field is required to be unique.
* @returns {Field} - A new Field. * @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( public constructor(
id: number, id: number,
appId: number, appId: number,
name: string, name: string,
type: string, type: FieldType,
status: string, status: FieldStatus,
isRequired: boolean, isRequired: boolean,
isUnique: 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.id = id;
this.appId = appId; this.appId = appId;
this.name = name; this.name = name;
this.type = FieldType[type]; this.type = type;
this.status = FieldStatus[status]; this.status = status;
this.isRequired = isRequired; this.isRequired = isRequired;
this.isUnique = isUnique; this.isUnique = isUnique;
} }
+10 -16
View File
@@ -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 { Field } from './Field';
import { type ListValue } from './ListValue'; 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} id - The id of the formula field.
* @param {number} appId - The id of the app the formula field belongs to. * @param {number} appId - The id of the app the formula field belongs to.
* @param {string} name - The name of the formula field. * @param {string} name - The name of the formula field.
* @param {string} type - The type of the formula field. * @param {FieldType} type - The type of the formula field.
* @param {string} status - The status of the formula field. * @param {FieldStatus} status - The status of the formula field.
* @param {boolean} isRequired - Whether the formula field is required. * @param {boolean} isRequired - Whether the formula field is required.
* @param {boolean} isUnique - Whether the formula field is unique. * @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. * @param {ListValue[]} values - The list values of the formula field.
* @returns {FormulaField} - A new FormulaField. * @returns {FormulaField} - A new FormulaField.
* @throws {Error} - Throws an error if the outputType is not a valid FormulaOutputType.
*/ */
constructor( constructor(
id: number, id: number,
appId: number, appId: number,
name: string, name: string,
type: string, type: FieldType,
status: string, status: FieldStatus,
isRequired: boolean, isRequired: boolean,
isUnique: boolean, isUnique: boolean,
outputType: string, outputType: FormulaOutputType,
values: ListValue[] values: ListValue[]
) { ) {
super(id, appId, name, type, status, isRequired, isUnique); super(id, appId, name, type, status, isRequired, isUnique);
this.outputType = outputType;
if (FormulaOutputType[outputType] === undefined) {
throw new Error(
`The outputType ${outputType} is not a valid FormulaOutputType.`
);
}
this.outputType = FormulaOutputType[outputType];
this.values = values; this.values = values;
} }
} }
+10 -16
View File
@@ -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 { Field } from './Field';
import { type ListValue } from './ListValue'; 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} id - The id of the list field.
* @param {number} appId - The id of the app the list field belongs to. * @param {number} appId - The id of the app the list field belongs to.
* @param {string} name - The name of the list field. * @param {string} name - The name of the list field.
* @param {string} type - The type of the list field. * @param {FieldType} type - The type of the list field.
* @param {string} status - The status of the list field. * @param {FieldStatus} status - The status of the list field.
* @param {boolean} isRequired - Whether the list field is required. * @param {boolean} isRequired - Whether the list field is required.
* @param {boolean} isUnique - Whether the list field is unique. * @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 {number} listId - The id of the list the list field belongs to.
* @param {ListValue[]} values - The list values of the list field. * @param {ListValue[]} values - The list values of the list field.
* @returns {ListField} - A new ListField. * @returns {ListField} - A new ListField.
* @throws {Error} - Throws an error if the multiplicity is not a valid Multiplicity.
*/ */
constructor( constructor(
id: number, id: number,
appId: number, appId: number,
name: string, name: string,
type: string, type: FieldType,
status: string, status: FieldStatus,
isRequired: boolean, isRequired: boolean,
isUnique: boolean, isUnique: boolean,
multiplicity: string, multiplicity: Multiplicity,
listId: number, listId: number,
values: ListValue[] values: ListValue[]
) { ) {
super(id, appId, name, type, status, isRequired, isUnique); super(id, appId, name, type, status, isRequired, isUnique);
this.multiplicity = multiplicity;
if (Multiplicity[multiplicity] === undefined) {
throw new Error(
`The multiplicity ${multiplicity} is not a valid Multiplicity.`
);
}
this.multiplicity = Multiplicity[multiplicity];
this.listId = listId; this.listId = listId;
this.values = values; this.values = values;
} }
+1 -1
View File
@@ -23,7 +23,7 @@ export class ListValue {
public numericValue: number; public numericValue: number;
/** /**
* * @property {string} color - The color of the list value.
*/ */
public color: string; public color: string;
+2 -2
View File
@@ -7,12 +7,12 @@ export class PagingRequest {
/** /**
* @property {number} pageNumber - The page number of the request. * @property {number} pageNumber - The page number of the request.
*/ */
pageNumber: number; public pageNumber: number;
/** /**
* @property {number} pageSize - The page size of the request. * @property {number} pageSize - The page size of the request.
*/ */
pageSize: number; public pageSize: number;
/** /**
* @constructor - Creates a new instance of the PagingRequest class. * @constructor - Creates a new instance of the PagingRequest class.
+38
View File
@@ -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<RecordValue<any>>} fieldData - The data for the fields in the record.
*/
public fieldData: Array<RecordValue<any>>;
/**
* @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<RecordValue<any>>} fieldData - The data for the fields in the record.
* @returns {Record} - A new instance of Record.
*/
constructor(
appId: number,
recordId: number,
fieldData: Array<RecordValue<any>>
) {
this.appId = appId;
this.recordId = recordId;
this.fieldData = fieldData;
}
}
+34
View File
@@ -0,0 +1,34 @@
import { type RecordValueType } from '../enums/RecordValueType';
/**
* @class RecordValue - A value for a field in a record.
*/
export class RecordValue<T> {
/**
* @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;
}
}
+10 -16
View File
@@ -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 { Field } from './Field';
/** /**
@@ -20,35 +22,27 @@ export class ReferenceField extends Field {
* @param {number} id - The id of the reference field. * @param {number} id - The id of the reference field.
* @param {number} appId - The id of the app the reference field belongs to. * @param {number} appId - The id of the app the reference field belongs to.
* @param {string} name - The name of the reference field. * @param {string} name - The name of the reference field.
* @param {string} type - The type of the reference field. * @param {FieldType} type - The type of the reference field.
* @param {string} status - The status of the reference field. * @param {FieldStatus} status - The status of the reference field.
* @param {boolean} isRequired - Whether the reference field is required. * @param {boolean} isRequired - Whether the reference field is required.
* @param {boolean} isUnique - Whether the reference field is unique. * @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. * @param {number} referencedAppId - The id of the app the reference field references.
* @returns {ReferenceField} - A new ReferenceField. * @returns {ReferenceField} - A new ReferenceField.
* @throws {Error} - Throws an error if the multiplicity is not a valid Multiplicity.jjkdleroritlasaxmvjd
*/ */
constructor( constructor(
id: number, id: number,
appId: number, appId: number,
name: string, name: string,
type: string, type: FieldType,
status: string, status: FieldStatus,
isRequired: boolean, isRequired: boolean,
isUnique: boolean, isUnique: boolean,
multiplicity: string, multiplicity: Multiplicity,
referencedAppId: number referencedAppId: number
) { ) {
super(id, appId, name, type, status, isRequired, isUnique); super(id, appId, name, type, status, isRequired, isUnique);
this.multiplicity = multiplicity;
if (Multiplicity[multiplicity] === undefined) {
throw new Error(
`The multiplicity ${multiplicity} is not a valid Multiplicity.`
);
}
this.multiplicity = Multiplicity[multiplicity];
this.referencedAppId = referencedAppId; this.referencedAppId = referencedAppId;
} }
} }
+18 -2
View File
@@ -1,8 +1,24 @@
/**
* @class Row - Represents a row of data in a report.
*/
export class Row { export class Row {
/**
* @property {number} recordId - The id of the record that the row represents.
*/
public recordId: number; 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.recordId = recordId;
this.cells = cells; this.cells = cells;
} }
+44
View File
@@ -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;
}
}
+49
View File
@@ -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;
}
}
+6
View File
@@ -0,0 +1,6 @@
import { Attachment } from '../src/models/Attachment';
import { expect } from 'chai';
describe('Attachment', function () {
throw new Error('Not implemented');
});
+28 -28
View File
@@ -1,4 +1,6 @@
import { expect } from 'chai'; import { expect } from 'chai';
import { FieldStatus } from '../src/enums/FieldStatus';
import { FieldType } from '../src/enums/FieldType';
import { Field } from '../src/models/Field'; import { Field } from '../src/models/Field';
describe('Field', function () { describe('Field', function () {
@@ -16,38 +18,36 @@ describe('Field', function () {
it('should create a new instance of the Field class', function () { it('should create a new instance of the Field class', function () {
expect( 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(); ).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 () { 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('id', 1);
expect(field).to.have.property('appId'); expect(field).to.have.property('appId', 1);
expect(field).to.have.property('name'); expect(field).to.have.property('name', 'Text Field');
expect(field).to.have.property('type'); expect(field).to.have.property('type', FieldType.Text);
expect(field).to.have.property('status'); expect(field).to.have.property('status', FieldStatus.Enabled);
expect(field).to.have.property('isRequired'); expect(field).to.have.property('isRequired', true);
expect(field).to.have.property('isUnique'); expect(field).to.have.property('isUnique', false);
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);
}); });
}); });
+12 -26
View File
@@ -1,5 +1,8 @@
import { FormulaField } from '../src/models/FormulaField'; import { FormulaField } from '../src/models/FormulaField';
import { expect } from 'chai'; 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 () { describe('FormulaField', function () {
it('should be defined', function () { it('should be defined', function () {
@@ -14,33 +17,16 @@ describe('FormulaField', function () {
expect(FormulaField).to.have.property('constructor'); 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 () { it('should create a new FormulaField', function () {
const formulaField = new FormulaField( const formulaField = new FormulaField(
1, 1,
1, 1,
'Formula Field', 'Formula Field',
'Formula', FieldType.Formula,
'Enabled', FieldStatus.Enabled,
false, false,
false, false,
'Text', FormulaOutputType.Text,
[] []
); );
expect(formulaField).to.be.an.instanceOf(FormulaField); expect(formulaField).to.be.an.instanceOf(FormulaField);
@@ -51,11 +37,11 @@ describe('FormulaField', function () {
1, 1,
1, 1,
'Formula Field', 'Formula Field',
'Formula', FieldType.Formula,
'Enabled', FieldStatus.Enabled,
false, false,
false, false,
'Text', FormulaOutputType.Text,
[] []
); );
expect(formulaField).to.have.property('outputType'); expect(formulaField).to.have.property('outputType');
@@ -66,11 +52,11 @@ describe('FormulaField', function () {
1, 1,
1, 1,
'Formula Field', 'Formula Field',
'Formula', FieldType.Formula,
'Enabled', FieldStatus.Enabled,
false, false,
false, false,
'Text', FormulaOutputType.Text,
[] []
); );
expect(formulaField).to.have.property('values'); expect(formulaField).to.have.property('values');
+13 -1
View File
@@ -1,6 +1,8 @@
import { GetPagedFieldsResponse } from '../src/models/GetPagedFieldsResponse'; import { GetPagedFieldsResponse } from '../src/models/GetPagedFieldsResponse';
import { Field } from '../src/models/Field'; import { Field } from '../src/models/Field';
import { expect } from 'chai'; import { expect } from 'chai';
import { FieldType } from '../src/enums/FieldType';
import { FieldStatus } from '../src/enums/FieldStatus';
describe('GetPagedFieldsResponse', function () { describe('GetPagedFieldsResponse', function () {
it('should be defined', function () { it('should be defined', function () {
@@ -17,7 +19,17 @@ describe('GetPagedFieldsResponse', function () {
it('should construct a new instance of GetPagedFieldsResponse', function () { it('should construct a new instance of GetPagedFieldsResponse', function () {
const getPagedFieldsResponse = new GetPagedFieldsResponse( 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, 1,
10, 10,
100, 100,
+15 -30
View File
@@ -1,5 +1,8 @@
import { ListField } from '../src/models/ListField'; import { ListField } from '../src/models/ListField';
import { expect } from 'chai'; 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 () { describe('ListField', function () {
it('should be defined', function () { it('should be defined', function () {
@@ -14,34 +17,16 @@ describe('ListField', function () {
expect(ListField).to.have.property('constructor'); 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 () { it('should create a new ListField', function () {
const listField = new ListField( const listField = new ListField(
1, 1,
1, 1,
'List Field', 'List Field',
'List', FieldType.List,
'Enabled', FieldStatus.Enabled,
false, false,
false, false,
'SingleSelect', Multiplicity.SingleSelect,
1, 1,
[] []
); );
@@ -53,11 +38,11 @@ describe('ListField', function () {
1, 1,
1, 1,
'List Field', 'List Field',
'List', FieldType.List,
'Enabled', FieldStatus.Enabled,
false, false,
false, false,
'SingleSelect', Multiplicity.SingleSelect,
1, 1,
[] []
); );
@@ -69,11 +54,11 @@ describe('ListField', function () {
1, 1,
1, 1,
'List Field', 'List Field',
'List', FieldType.List,
'Enabled', FieldStatus.Enabled,
false, false,
false, false,
'SingleSelect', Multiplicity.SingleSelect,
1, 1,
[] []
); );
@@ -85,11 +70,11 @@ describe('ListField', function () {
1, 1,
1, 1,
'List Field', 'List Field',
'List', FieldType.List,
'Enabled', FieldStatus.Enabled,
false, false,
false, false,
'SingleSelect', Multiplicity.SingleSelect,
1, 1,
[] []
); );
+89
View File
@@ -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');
});
});
+46
View File
@@ -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');
});
});
@@ -1,87 +1,87 @@
import { ResultValueType } from '../src/enums/ResultValueType'; import { RecordValueType } from '../src/enums/RecordValueType';
import { expect } from 'chai'; import { expect } from 'chai';
describe('ResultValueType', function () { describe('RecordValueType', function () {
describe('String', function () { describe('String', function () {
it('should return the correct value', function () { it('should return the correct value', function () {
const result = ResultValueType.String; const result = RecordValueType.String;
expect(result).to.equal('String'); expect(result).to.equal('String');
}); });
}); });
describe('Integer', function () { describe('Integer', function () {
it('should return the correct value', function () { it('should return the correct value', function () {
const result = ResultValueType.Integer; const result = RecordValueType.Integer;
expect(result).to.equal('Integer'); expect(result).to.equal('Integer');
}); });
}); });
describe('Decimal', function () { describe('Decimal', function () {
it('should return the correct value', function () { it('should return the correct value', function () {
const result = ResultValueType.Decimal; const result = RecordValueType.Decimal;
expect(result).to.equal('Decimal'); expect(result).to.equal('Decimal');
}); });
}); });
describe('Date', function () { describe('Date', function () {
it('should return the correct value', function () { it('should return the correct value', function () {
const result = ResultValueType.Date; const result = RecordValueType.Date;
expect(result).to.equal('Date'); expect(result).to.equal('Date');
}); });
}); });
describe('TimeSpan', function () { describe('TimeSpan', function () {
it('should return the correct value', function () { it('should return the correct value', function () {
const result = ResultValueType.TimeSpan; const result = RecordValueType.TimeSpan;
expect(result).to.equal('TimeSpan'); expect(result).to.equal('TimeSpan');
}); });
}); });
describe('Guid', function () { describe('Guid', function () {
it('should return the correct value', function () { it('should return the correct value', function () {
const result = ResultValueType.Guid; const result = RecordValueType.Guid;
expect(result).to.equal('Guid'); expect(result).to.equal('Guid');
}); });
}); });
describe('StringList', function () { describe('StringList', function () {
it('should return the correct value', function () { it('should return the correct value', function () {
const result = ResultValueType.StringList; const result = RecordValueType.StringList;
expect(result).to.equal('StringList'); expect(result).to.equal('StringList');
}); });
}); });
describe('IntegerList', function () { describe('IntegerList', function () {
it('should return the correct value', function () { it('should return the correct value', function () {
const result = ResultValueType.IntegerList; const result = RecordValueType.IntegerList;
expect(result).to.equal('IntegerList'); expect(result).to.equal('IntegerList');
}); });
}); });
describe('GuidList', function () { describe('GuidList', function () {
it('should return the correct value', function () { it('should return the correct value', function () {
const result = ResultValueType.GuidList; const result = RecordValueType.GuidList;
expect(result).to.equal('GuidList'); expect(result).to.equal('GuidList');
}); });
}); });
describe('AttachmentList', function () { describe('AttachmentList', function () {
it('should return the correct value', function () { it('should return the correct value', function () {
const result = ResultValueType.AttachmentList; const result = RecordValueType.AttachmentList;
expect(result).to.equal('AttachmentList'); expect(result).to.equal('AttachmentList');
}); });
}); });
describe('ScoringGroupList', function () { describe('ScoringGroupList', function () {
it('should return the correct value', function () { it('should return the correct value', function () {
const result = ResultValueType.ScoringGroupList; const result = RecordValueType.ScoringGroupList;
expect(result).to.equal('ScoringGroupList'); expect(result).to.equal('ScoringGroupList');
}); });
}); });
describe('FileList', function () { describe('FileList', function () {
it('should return the correct value', function () { it('should return the correct value', function () {
const result = ResultValueType.FileList; const result = RecordValueType.FileList;
expect(result).to.equal('FileList'); expect(result).to.equal('FileList');
}); });
}); });
+12 -26
View File
@@ -1,5 +1,8 @@
import { ReferenceField } from '../src/models/ReferenceField'; import { ReferenceField } from '../src/models/ReferenceField';
import { expect } from 'chai'; 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 () { describe('ReferenceField', function () {
it('should be defined', function () { it('should be defined', function () {
@@ -14,33 +17,16 @@ describe('ReferenceField', function () {
expect(ReferenceField).to.have.property('constructor'); 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 () { it('should create a new ReferenceField', function () {
const referenceField = new ReferenceField( const referenceField = new ReferenceField(
1, 1,
1, 1,
'Reference Field', 'Reference Field',
'Reference', FieldType.Reference,
'Enabled', FieldStatus.Enabled,
false, false,
false, false,
'SingleSelect', Multiplicity.SingleSelect,
1 1
); );
expect(referenceField).to.be.an.instanceOf(ReferenceField); expect(referenceField).to.be.an.instanceOf(ReferenceField);
@@ -51,11 +37,11 @@ describe('ReferenceField', function () {
1, 1,
1, 1,
'Reference Field', 'Reference Field',
'Reference', FieldType.Reference,
'Enabled', FieldStatus.Enabled,
false, false,
false, false,
'SingleSelect', Multiplicity.SingleSelect,
1 1
); );
expect(referenceField).to.have.property('multiplicity'); expect(referenceField).to.have.property('multiplicity');
@@ -66,11 +52,11 @@ describe('ReferenceField', function () {
1, 1,
1, 1,
'Reference Field', 'Reference Field',
'Reference', FieldType.Reference,
'Enabled', FieldStatus.Enabled,
false, false,
false, false,
'SingleSelect', Multiplicity.SingleSelect,
1 1
); );
expect(referenceField).to.have.property('referencedAppId'); expect(referenceField).to.have.property('referencedAppId');
+24
View File
@@ -27,4 +27,28 @@ describe('Report', function () {
expect(report.name).to.be.equal('report'); expect(report.name).to.be.equal('report');
expect(report.description).to.be.equal('report description'); 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'
);
});
}); });
+8
View File
@@ -47,4 +47,12 @@ describe('ReportData', function () {
.with.lengthOf(2); .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');
});
}); });
+8
View File
@@ -16,4 +16,12 @@ describe('Row', function () {
expect(row).to.have.property('recordId', 1); expect(row).to.have.property('recordId', 1);
expect(row).to.have.property('cells').that.is.an('array').with.lengthOf(2); 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');
});
}); });
+6
View File
@@ -0,0 +1,6 @@
import { ScoringGroup } from '../src/models/ScoringGroup';
import { expect } from 'chai';
describe('ScoringGroup', function () {
throw new Error('Not implemented');
});
+6
View File
@@ -0,0 +1,6 @@
import { TimeSpanData } from '../src/models/TimeSpanData';
import { expect } from 'chai';
describe('TimeSpanData', function () {
throw new Error('Not implemented');
});