fix: refactor to have child classes that inherit from RecordValue, but represent the distinct types of value objects that can be returned by the api. fix: added and updated tests to address this refactor
This commit is contained in:
@@ -72,4 +72,10 @@ export enum RecordValueType {
|
|||||||
* @type {string}
|
* @type {string}
|
||||||
*/
|
*/
|
||||||
FileList = 'FileList',
|
FileList = 'FileList',
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @constant DelegateList - The record value is a list of delegates.
|
||||||
|
* @type {string}
|
||||||
|
*/
|
||||||
|
DelegateList = 'DelegateList',
|
||||||
}
|
}
|
||||||
|
|||||||
+267
-23
@@ -1,28 +1,50 @@
|
|||||||
import { type AxiosResponse } from 'axios';
|
import { type AxiosResponse } from 'axios';
|
||||||
|
import { DelegateType } from '../enums/DelegateType';
|
||||||
import { FieldStatus } from '../enums/FieldStatus';
|
import { FieldStatus } from '../enums/FieldStatus';
|
||||||
import { FieldType } from '../enums/FieldType';
|
import { FieldType } from '../enums/FieldType';
|
||||||
|
import { FileStorageSite } from '../enums/FileStorageSite';
|
||||||
import { FormulaOutputType } from '../enums/FormulaOutputType';
|
import { FormulaOutputType } from '../enums/FormulaOutputType';
|
||||||
import { Multiplicity } from '../enums/Multiplicity';
|
import { Multiplicity } from '../enums/Multiplicity';
|
||||||
|
import { RecordValueType } from '../enums/RecordValueType';
|
||||||
|
import { TimeSpanIncrement } from '../enums/TimeSpanIncrement';
|
||||||
|
import { TimeSpanRecurrenceType } from '../enums/TimeSpanRecurrenceType';
|
||||||
import { App } from './App';
|
import { App } from './App';
|
||||||
|
import { Attachment } from './Attachment';
|
||||||
|
import { AttachmentListRecordValue } from './AttachmentListRecordValue';
|
||||||
import { CollectionResponse } from './CollectionResponse';
|
import { CollectionResponse } from './CollectionResponse';
|
||||||
import { CreatedWithIdResponse } from './CreatedWithIdResponse';
|
import { CreatedWithIdResponse } from './CreatedWithIdResponse';
|
||||||
|
import { DateRecordValue } from './DateRecordValue';
|
||||||
|
import { DecimalRecordValue } from './DecimalRecordValue';
|
||||||
|
import { Delegate } from './Delegate';
|
||||||
|
import { DelegateListRecordValue } from './DelegateListRecordValue';
|
||||||
import { Field } from './Field';
|
import { Field } from './Field';
|
||||||
import { File } from './File';
|
import { File } from './File';
|
||||||
import { FileInfo } from './FileInfo';
|
import { FileInfo } from './FileInfo';
|
||||||
|
import { FileListRecordValue } from './FileListRecordValue';
|
||||||
import { FormulaField } from './FormulaField';
|
import { FormulaField } from './FormulaField';
|
||||||
import { GetPagedAppsResponse } from './GetPagedAppsResponse';
|
import { GetPagedAppsResponse } from './GetPagedAppsResponse';
|
||||||
import { GetPagedFieldsResponse } from './GetPagedFieldsResponse';
|
import { GetPagedFieldsResponse } from './GetPagedFieldsResponse';
|
||||||
import { GetPagedRecordsResponse } from './GetPagedRecordsResponse';
|
import { GetPagedRecordsResponse } from './GetPagedRecordsResponse';
|
||||||
import { GetPagedReportsResponse } from './GetPagedReportsResponse';
|
import { GetPagedReportsResponse } from './GetPagedReportsResponse';
|
||||||
|
import { GuidListRecordValue } from './GuidListRecordValue';
|
||||||
|
import { GuidRecordValue } from './GuidRecordValue';
|
||||||
|
import { IntegerListRecordValue } from './IntegerListRecordValue';
|
||||||
|
import { IntegerRecordValue } from './IntegerRecordValue';
|
||||||
import { ListField } from './ListField';
|
import { ListField } from './ListField';
|
||||||
import { ListItemResponse } from './ListItemResponse';
|
import { ListItemResponse } from './ListItemResponse';
|
||||||
import { ListValue } from './ListValue';
|
import { ListValue } from './ListValue';
|
||||||
import { Record } from './Record';
|
import { Record } from './Record';
|
||||||
import { RecordValue } from './RecordValue';
|
|
||||||
import { ReferenceField } from './ReferenceField';
|
import { ReferenceField } from './ReferenceField';
|
||||||
import { Report } from './Report';
|
import { Report } from './Report';
|
||||||
import { ReportData } from './ReportData';
|
import { ReportData } from './ReportData';
|
||||||
import { Row } from './Row';
|
import { Row } from './Row';
|
||||||
|
import { ScoringGroup } from './ScoringGroup';
|
||||||
|
import { ScoringGroupListRecordValue } from './ScoringGroupListRecordValue';
|
||||||
|
import { StringListRecordValue } from './StringListRecordValue';
|
||||||
|
import { StringRecordValue } from './StringRecordValue';
|
||||||
|
import { TimeSpanData } from './TimeSpanData';
|
||||||
|
import { TimeSpanRecordValue } from './TimeSpanRecordValue';
|
||||||
|
import { type RecordValue } from './RecordValue';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @class ApiResponse - A generic response object for API requests.
|
* @class ApiResponse - A generic response object for API requests.
|
||||||
@@ -339,13 +361,10 @@ export class ApiResponse<T> {
|
|||||||
const apiResponse = this as ApiResponse<any>;
|
const apiResponse = this as ApiResponse<any>;
|
||||||
|
|
||||||
const records = apiResponse.data.items.map((item: any) => {
|
const records = apiResponse.data.items.map((item: any) => {
|
||||||
const recordValues = item.fieldData.map((fieldData: any) => {
|
const recordValues = item.fieldData.map((recordValueItem: any) =>
|
||||||
return new RecordValue(
|
ApiResponse.getRecordValueByType(recordValueItem)
|
||||||
fieldData.type,
|
);
|
||||||
fieldData.fieldId,
|
|
||||||
fieldData.value
|
|
||||||
);
|
|
||||||
});
|
|
||||||
return new Record(item.appId, item.recordId, recordValues);
|
return new Record(item.appId, item.recordId, recordValues);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -371,13 +390,10 @@ export class ApiResponse<T> {
|
|||||||
public asRecordType(): ApiResponse<Record> {
|
public asRecordType(): ApiResponse<Record> {
|
||||||
const apiResponse = this as ApiResponse<any>;
|
const apiResponse = this as ApiResponse<any>;
|
||||||
|
|
||||||
const recordValues = apiResponse.data.fieldData.map((fieldData: any) => {
|
const recordValues = apiResponse.data.fieldData.map(
|
||||||
return new RecordValue(
|
(recordValueItem: any) =>
|
||||||
fieldData.type,
|
ApiResponse.getRecordValueByType(recordValueItem)
|
||||||
fieldData.fieldId,
|
);
|
||||||
fieldData.value
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
const record = new Record(
|
const record = new Record(
|
||||||
apiResponse.data.appId,
|
apiResponse.data.appId,
|
||||||
@@ -396,13 +412,10 @@ export class ApiResponse<T> {
|
|||||||
const apiResponse = this as ApiResponse<any>;
|
const apiResponse = this as ApiResponse<any>;
|
||||||
|
|
||||||
const records = apiResponse.data.items.map((item: any) => {
|
const records = apiResponse.data.items.map((item: any) => {
|
||||||
const recordValues = item.fieldData.map((fieldData: any) => {
|
const recordValues = item.fieldData.map((recordValueItem: any) =>
|
||||||
return new RecordValue(
|
ApiResponse.getRecordValueByType(recordValueItem)
|
||||||
fieldData.type,
|
);
|
||||||
fieldData.fieldId,
|
|
||||||
fieldData.value
|
|
||||||
);
|
|
||||||
});
|
|
||||||
return new Record(item.appId, item.recordId, recordValues);
|
return new Record(item.appId, item.recordId, recordValues);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -418,8 +431,113 @@ export class ApiResponse<T> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static getRecordValueByType(recordValueItem: any): RecordValue<any> {
|
||||||
|
const type = RecordValueType[recordValueItem.type];
|
||||||
|
|
||||||
|
switch (type) {
|
||||||
|
case RecordValueType.String: {
|
||||||
|
return new StringRecordValue(
|
||||||
|
recordValueItem.fieldId,
|
||||||
|
recordValueItem.value
|
||||||
|
);
|
||||||
|
}
|
||||||
|
case RecordValueType.Integer: {
|
||||||
|
return new IntegerRecordValue(
|
||||||
|
recordValueItem.fieldId,
|
||||||
|
recordValueItem.value
|
||||||
|
);
|
||||||
|
}
|
||||||
|
case RecordValueType.Decimal: {
|
||||||
|
return new DecimalRecordValue(
|
||||||
|
recordValueItem.fieldId,
|
||||||
|
recordValueItem.value
|
||||||
|
);
|
||||||
|
}
|
||||||
|
case RecordValueType.Date: {
|
||||||
|
const date = new Date(recordValueItem.value);
|
||||||
|
return new DateRecordValue(recordValueItem.fieldId, date);
|
||||||
|
}
|
||||||
|
case RecordValueType.TimeSpan: {
|
||||||
|
const timeSpan = ApiResponse.convertToTimeSpanData(
|
||||||
|
recordValueItem.value
|
||||||
|
);
|
||||||
|
return new TimeSpanRecordValue(recordValueItem.fieldId, timeSpan);
|
||||||
|
}
|
||||||
|
case RecordValueType.Guid: {
|
||||||
|
return new GuidRecordValue(
|
||||||
|
recordValueItem.fieldId,
|
||||||
|
recordValueItem.value
|
||||||
|
);
|
||||||
|
}
|
||||||
|
case RecordValueType.StringList: {
|
||||||
|
return new StringListRecordValue(
|
||||||
|
recordValueItem.fieldId,
|
||||||
|
recordValueItem.value
|
||||||
|
);
|
||||||
|
}
|
||||||
|
case RecordValueType.IntegerList: {
|
||||||
|
return new IntegerListRecordValue(
|
||||||
|
recordValueItem.fieldId,
|
||||||
|
recordValueItem.value
|
||||||
|
);
|
||||||
|
}
|
||||||
|
case RecordValueType.GuidList: {
|
||||||
|
return new GuidListRecordValue(
|
||||||
|
recordValueItem.fieldId,
|
||||||
|
recordValueItem.value
|
||||||
|
);
|
||||||
|
}
|
||||||
|
case RecordValueType.AttachmentList: {
|
||||||
|
const attachments = recordValueItem.value.map((attachmentItem: any) =>
|
||||||
|
ApiResponse.convertToAttachment(attachmentItem)
|
||||||
|
);
|
||||||
|
|
||||||
|
return new AttachmentListRecordValue(
|
||||||
|
recordValueItem.fieldId,
|
||||||
|
attachments
|
||||||
|
);
|
||||||
|
}
|
||||||
|
case RecordValueType.ScoringGroupList: {
|
||||||
|
const array = recordValueItem.value as any[];
|
||||||
|
const isDelegateList = array[0].delegateType !== undefined;
|
||||||
|
|
||||||
|
if (isDelegateList) {
|
||||||
|
const delegates = recordValueItem.value.map((delegateItem: any) =>
|
||||||
|
ApiResponse.convertToDelegate(delegateItem)
|
||||||
|
);
|
||||||
|
|
||||||
|
return new DelegateListRecordValue(
|
||||||
|
recordValueItem.fieldId,
|
||||||
|
delegates
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const scoringGroups = recordValueItem.value.map(
|
||||||
|
(scoringGroupItem: any) =>
|
||||||
|
ApiResponse.convertToScoringGroup(scoringGroupItem)
|
||||||
|
);
|
||||||
|
|
||||||
|
return new ScoringGroupListRecordValue(
|
||||||
|
recordValueItem.fieldId,
|
||||||
|
scoringGroups
|
||||||
|
);
|
||||||
|
}
|
||||||
|
case RecordValueType.FileList: {
|
||||||
|
return new FileListRecordValue(
|
||||||
|
recordValueItem.fieldId,
|
||||||
|
recordValueItem.value
|
||||||
|
);
|
||||||
|
}
|
||||||
|
default: {
|
||||||
|
throw new Error(
|
||||||
|
`Unknown record value type: ${recordValueItem.type as string}`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @method asFileCollectionType - Converts the field item to the appropriate field object based upon the field item's type.
|
* @method getFieldByType - Converts the field item to the appropriate field object based upon the field item's type.
|
||||||
* @param {any} fieldItem - The field item to convert.
|
* @param {any} fieldItem - The field item to convert.
|
||||||
* @returns {Field} - The converted field object.
|
* @returns {Field} - The converted field object.
|
||||||
* @throws {Error} - If the field item's type is unknown.
|
* @throws {Error} - If the field item's type is unknown.
|
||||||
@@ -495,6 +613,132 @@ export class ApiResponse<T> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static convertToDelegate(delegateItem: any): Delegate {
|
||||||
|
const delegateType = DelegateType[delegateItem.delegateType];
|
||||||
|
|
||||||
|
if (delegateType === undefined) {
|
||||||
|
throw new Error(
|
||||||
|
`${delegateItem.delegateType as string} is not a valid DelegateType.`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const delegationDateTime = new Date(delegateItem.delegationDateTime);
|
||||||
|
|
||||||
|
const hasName =
|
||||||
|
delegateItem.name !== null && delegateItem.name !== undefined;
|
||||||
|
const name = hasName ? delegateItem.name : null;
|
||||||
|
|
||||||
|
const hasCompletionDate =
|
||||||
|
delegateItem.delegationCompletedDateTime !== null &&
|
||||||
|
delegateItem.delegationCompletedDateTime !== undefined;
|
||||||
|
|
||||||
|
const delegationCompletedDateTime = hasCompletionDate
|
||||||
|
? new Date(delegateItem.delegationCompletedDateTime)
|
||||||
|
: null;
|
||||||
|
|
||||||
|
return new Delegate(
|
||||||
|
delegateItem.delegateType,
|
||||||
|
name,
|
||||||
|
delegateItem.emailAddress,
|
||||||
|
delegationDateTime,
|
||||||
|
delegationCompletedDateTime
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @method convertToScoringGroup - Converts the scoring group item to the appropriate scoring group object.
|
||||||
|
* @param {any} scoringGroupItem - The scoring group item to convert.
|
||||||
|
* @returns {ScoringGroup} - The converted scoring group object.
|
||||||
|
*/
|
||||||
|
private static convertToScoringGroup(scoringGroupItem: any): ScoringGroup {
|
||||||
|
return new ScoringGroup(
|
||||||
|
scoringGroupItem.id,
|
||||||
|
scoringGroupItem.name,
|
||||||
|
scoringGroupItem.score,
|
||||||
|
scoringGroupItem.maximumScore
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @method convertToAttachment - Converts the attachment item to the appropriate attachment object.
|
||||||
|
* @param {any} attachmentItem - The attachment item to convert.
|
||||||
|
* @returns {Attachment} - The converted attachment object.
|
||||||
|
*/
|
||||||
|
private static convertToAttachment(attachmentItem: any): Attachment {
|
||||||
|
const storageLocation = FileStorageSite[attachmentItem.storageLocation];
|
||||||
|
|
||||||
|
if (storageLocation === undefined) {
|
||||||
|
throw new Error(
|
||||||
|
`${
|
||||||
|
attachmentItem.storageLocation as string
|
||||||
|
} is not a valid FileStorageSite.`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const hasNotes =
|
||||||
|
attachmentItem.notes !== null && attachmentItem.notes !== undefined;
|
||||||
|
|
||||||
|
const notes = hasNotes ? attachmentItem.notes : null;
|
||||||
|
|
||||||
|
return new Attachment(
|
||||||
|
attachmentItem.fileId,
|
||||||
|
attachmentItem.fileName,
|
||||||
|
notes,
|
||||||
|
storageLocation
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @method convertToTimeSpanData - Converts the time span item to the appropriate time span data object.
|
||||||
|
* @param {any} timeSpanItem - The time span item to convert.
|
||||||
|
* @returns {TimeSpanData} - The converted time span data object.
|
||||||
|
*/
|
||||||
|
private static convertToTimeSpanData(timeSpanItem: any): TimeSpanData {
|
||||||
|
const increment = TimeSpanIncrement[timeSpanItem.increment];
|
||||||
|
|
||||||
|
const hasRecurrence =
|
||||||
|
timeSpanItem.recurrence !== null && timeSpanItem.recurrence !== undefined;
|
||||||
|
|
||||||
|
const recurrene = hasRecurrence
|
||||||
|
? TimeSpanRecurrenceType[timeSpanItem.recurrence]
|
||||||
|
: null;
|
||||||
|
|
||||||
|
const hasEndAfterOccurrences =
|
||||||
|
timeSpanItem.endAfterOccurrences !== null &&
|
||||||
|
timeSpanItem.endAfterOccurrences !== undefined;
|
||||||
|
|
||||||
|
const endAfterOccurrences = hasEndAfterOccurrences
|
||||||
|
? timeSpanItem.endAfterOccurrences
|
||||||
|
: null;
|
||||||
|
|
||||||
|
const hasEndByDate =
|
||||||
|
timeSpanItem.endByDate !== null && timeSpanItem.endByDate !== undefined;
|
||||||
|
|
||||||
|
const endByDate = hasEndByDate ? new Date(timeSpanItem.endByDate) : null;
|
||||||
|
|
||||||
|
if (increment === undefined) {
|
||||||
|
throw new Error(
|
||||||
|
`${timeSpanItem.increment as string} is not a valid TimeSpanIncrement.`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (recurrene === undefined) {
|
||||||
|
throw new Error(
|
||||||
|
`${
|
||||||
|
timeSpanItem.recurrence as string
|
||||||
|
} is not a valid TimeSpanRecurrenceType.`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return new TimeSpanData(
|
||||||
|
timeSpanItem.quantity,
|
||||||
|
increment,
|
||||||
|
recurrene,
|
||||||
|
endAfterOccurrences,
|
||||||
|
endByDate
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @method getListValues - Converts the field items list values to a ListValue[].
|
* @method getListValues - Converts the field items list values to a ListValue[].
|
||||||
* @param fieldItem - The field item whose values should be converted.
|
* @param fieldItem - The field item whose values should be converted.
|
||||||
|
|||||||
@@ -0,0 +1,18 @@
|
|||||||
|
import { RecordValueType } from '../enums/RecordValueType';
|
||||||
|
import { type Attachment } from './Attachment';
|
||||||
|
import { RecordValue } from './RecordValue';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @class AttachmentListRecordValue - A record value represented by a list of attachments.
|
||||||
|
*/
|
||||||
|
export class AttachmentListRecordValue extends RecordValue<Attachment[]> {
|
||||||
|
/**
|
||||||
|
* @constructor - Creates a new instance of AttachmentListRecordValue.
|
||||||
|
* @param {number} fieldId - The id of the field.
|
||||||
|
* @param {Attachment[]} value - The value of the field.
|
||||||
|
* @returns {AttachmentListRecordValue} - A new instance of AttachmentListRecordValue.
|
||||||
|
*/
|
||||||
|
constructor(fieldId: number, value: Attachment[]) {
|
||||||
|
super(RecordValueType.AttachmentList, fieldId, value);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
import { RecordValueType } from '../enums/RecordValueType';
|
||||||
|
import { RecordValue } from './RecordValue';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @class DateRecordValue - A value for a date field in a record.
|
||||||
|
*/
|
||||||
|
export class DateRecordValue extends RecordValue<Date> {
|
||||||
|
/**
|
||||||
|
* @constructor - Creates a new instance of DateRecordValue.
|
||||||
|
* @param {number} fieldId - The id of the field.
|
||||||
|
* @param {Date} value - The value of the field.
|
||||||
|
* @returns {DateRecordValue} - A new instance of DateRecordValue.
|
||||||
|
*/
|
||||||
|
constructor(fieldId: number, value: Date) {
|
||||||
|
super(RecordValueType.Date, fieldId, value);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
import { RecordValue } from './RecordValue';
|
||||||
|
import { RecordValueType } from '../enums/RecordValueType';
|
||||||
|
|
||||||
|
export class DecimalRecordValue extends RecordValue<number> {
|
||||||
|
constructor(fieldId: number, value: number) {
|
||||||
|
super(RecordValueType.Decimal, fieldId, value);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
import { RecordValue } from './RecordValue';
|
||||||
|
import { RecordValueType } from '../enums/RecordValueType';
|
||||||
|
import { type Delegate } from './Delegate';
|
||||||
|
|
||||||
|
export class DelegateListRecordValue extends RecordValue<Delegate[]> {
|
||||||
|
constructor(fieldId: number, value: Delegate[]) {
|
||||||
|
super(RecordValueType.DelegateList, fieldId, value);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
import { RecordValue } from './RecordValue';
|
||||||
|
import { RecordValueType } from '../enums/RecordValueType';
|
||||||
|
import { type File } from './File';
|
||||||
|
|
||||||
|
export class FileListRecordValue extends RecordValue<File[]> {
|
||||||
|
constructor(fieldId: number, value: File[]) {
|
||||||
|
super(RecordValueType.FileList, fieldId, value);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
import { RecordValueType } from '../enums/RecordValueType';
|
||||||
|
import { RecordValue } from './RecordValue';
|
||||||
|
|
||||||
|
export class GuidListRecordValue extends RecordValue<string[]> {
|
||||||
|
constructor(fieldId: number, value: string[]) {
|
||||||
|
super(RecordValueType.GuidList, fieldId, value);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
import { RecordValueType } from '../enums/RecordValueType';
|
||||||
|
import { RecordValue } from './RecordValue';
|
||||||
|
|
||||||
|
export class GuidRecordValue extends RecordValue<string> {
|
||||||
|
constructor(fieldId: number, value: string) {
|
||||||
|
super(RecordValueType.Guid, fieldId, value);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
import { RecordValueType } from '../enums/RecordValueType';
|
||||||
|
import { RecordValue } from './RecordValue';
|
||||||
|
|
||||||
|
export class IntegerListRecordValue extends RecordValue<number[]> {
|
||||||
|
constructor(fieldId: number, value: number[]) {
|
||||||
|
super(RecordValueType.IntegerList, fieldId, value);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
import { RecordValueType } from '../enums/RecordValueType';
|
||||||
|
import { RecordValue } from './RecordValue';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @class IntegerRecordValue - A record value represented by an integer.
|
||||||
|
*/
|
||||||
|
export class IntegerRecordValue extends RecordValue<number> {
|
||||||
|
/**
|
||||||
|
* @constructor - Creates a new instance of IntegerRecordValue.
|
||||||
|
* @param {number} fieldId - The id of the field.
|
||||||
|
* @param {number} value - The value of the field.
|
||||||
|
* @returns {IntgerRecordValue} - A new instance of IntegerRecordValue.
|
||||||
|
*/
|
||||||
|
constructor(fieldId: number, value: number) {
|
||||||
|
super(RecordValueType.Integer, fieldId, value);
|
||||||
|
}
|
||||||
|
}
|
||||||
+21
-126
@@ -1,12 +1,12 @@
|
|||||||
import { DelegateType } from '../enums/DelegateType';
|
|
||||||
import { FileStorageSite } from '../enums/FileStorageSite';
|
|
||||||
import { RecordValueType } from '../enums/RecordValueType';
|
import { RecordValueType } from '../enums/RecordValueType';
|
||||||
import { TimeSpanIncrement } from '../enums/TimeSpanIncrement';
|
import { type Attachment } from './Attachment';
|
||||||
import { TimeSpanRecurrenceType } from '../enums/TimeSpanRecurrenceType';
|
import { type AttachmentListRecordValue } from './AttachmentListRecordValue';
|
||||||
import { Attachment } from './Attachment';
|
import { type Delegate } from './Delegate';
|
||||||
import { Delegate } from './Delegate';
|
import { type DelegateListRecordValue } from './DelegateListRecordValue';
|
||||||
import { ScoringGroup } from './ScoringGroup';
|
import { type ScoringGroup } from './ScoringGroup';
|
||||||
import { TimeSpanData } from './TimeSpanData';
|
import { type ScoringGroupListRecordValue } from './ScoringGroupListRecordValue';
|
||||||
|
import { type TimeSpanData } from './TimeSpanData';
|
||||||
|
import { type TimeSpanRecordValue } from './TimeSpanRecordValue';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @class RecordValue - A value for a field in a record.
|
* @class RecordValue - A value for a field in a record.
|
||||||
@@ -23,9 +23,9 @@ export class RecordValue<T> {
|
|||||||
public fieldId: number;
|
public fieldId: number;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @property {T | any} value - The value of the field.
|
* @property {T} value - The value of the field.
|
||||||
*/
|
*/
|
||||||
public value: T | any;
|
public value: T;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @constructor - Creates a new instance of RecordValue.
|
* @constructor - Creates a new instance of RecordValue.
|
||||||
@@ -34,7 +34,7 @@ export class RecordValue<T> {
|
|||||||
* @param {any} value - The value of the field.
|
* @param {any} value - The value of the field.
|
||||||
* @returns {RecordValue} - A new instance of RecordValue.
|
* @returns {RecordValue} - A new instance of RecordValue.
|
||||||
*/
|
*/
|
||||||
constructor(type: RecordValueType, fieldId: number, value: T | any) {
|
constructor(type: RecordValueType, fieldId: number, value: T) {
|
||||||
this.type = type;
|
this.type = type;
|
||||||
this.fieldId = fieldId;
|
this.fieldId = fieldId;
|
||||||
this.value = value;
|
this.value = value;
|
||||||
@@ -47,7 +47,7 @@ export class RecordValue<T> {
|
|||||||
*/
|
*/
|
||||||
public asString(): string {
|
public asString(): string {
|
||||||
this.validateType([RecordValueType.String, RecordValueType.Guid]);
|
this.validateType([RecordValueType.String, RecordValueType.Guid]);
|
||||||
return this.value;
|
return this.value as string;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -57,7 +57,7 @@ export class RecordValue<T> {
|
|||||||
*/
|
*/
|
||||||
public asNumber(): number {
|
public asNumber(): number {
|
||||||
this.validateType([RecordValueType.Integer, RecordValueType.Decimal]);
|
this.validateType([RecordValueType.Integer, RecordValueType.Decimal]);
|
||||||
return this.value;
|
return this.value as number;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -67,7 +67,7 @@ export class RecordValue<T> {
|
|||||||
*/
|
*/
|
||||||
public asDate(): Date {
|
public asDate(): Date {
|
||||||
this.validateType([RecordValueType.Date]);
|
this.validateType([RecordValueType.Date]);
|
||||||
return new Date(this.value);
|
return this.value as Date;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -78,29 +78,7 @@ export class RecordValue<T> {
|
|||||||
*/
|
*/
|
||||||
public asAttachmentArray(): Attachment[] {
|
public asAttachmentArray(): Attachment[] {
|
||||||
this.validateType([RecordValueType.AttachmentList]);
|
this.validateType([RecordValueType.AttachmentList]);
|
||||||
return this.value.map((attachment: any) => {
|
return (this as AttachmentListRecordValue).value;
|
||||||
const storageLocation = FileStorageSite[attachment.storageLocation];
|
|
||||||
|
|
||||||
if (storageLocation === undefined) {
|
|
||||||
throw new Error(
|
|
||||||
`${
|
|
||||||
this.value.storageLocation as string
|
|
||||||
} is not a valid FileStorageSite.`
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
const hasNotes =
|
|
||||||
attachment.notes !== null && attachment.notes !== undefined;
|
|
||||||
|
|
||||||
const notes = hasNotes ? attachment.notes : null;
|
|
||||||
|
|
||||||
return new Attachment(
|
|
||||||
attachment.fileId,
|
|
||||||
attachment.fileName,
|
|
||||||
notes,
|
|
||||||
storageLocation
|
|
||||||
);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -110,7 +88,7 @@ export class RecordValue<T> {
|
|||||||
*/
|
*/
|
||||||
public asNumberArray(): number[] {
|
public asNumberArray(): number[] {
|
||||||
this.validateType([RecordValueType.FileList, RecordValueType.IntegerList]);
|
this.validateType([RecordValueType.FileList, RecordValueType.IntegerList]);
|
||||||
return this.value;
|
return this.value as number[];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -120,47 +98,17 @@ export class RecordValue<T> {
|
|||||||
*/
|
*/
|
||||||
public asStringArray(): string[] {
|
public asStringArray(): string[] {
|
||||||
this.validateType([RecordValueType.StringList, RecordValueType.GuidList]);
|
this.validateType([RecordValueType.StringList, RecordValueType.GuidList]);
|
||||||
return this.value;
|
return this.value as string[];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @method asDelegateArray - Gets the value as an array of delegates.
|
* @method asDelegateArray - Gets the value as an array of delegates.
|
||||||
* @returns {Delegate[]} - The value as an array of delegates.
|
* @returns {Delegate[]} - The value as an array of delegates.
|
||||||
* @throws {Error} - If the value is not an array of delegates.
|
* @throws {Error} - If the value is not an array of delegates.
|
||||||
* @throws {Error} - If a delegate type is not valid.
|
|
||||||
*/
|
*/
|
||||||
public asDelegateArray(): Delegate[] {
|
public asDelegateArray(): Delegate[] {
|
||||||
this.validateType([RecordValueType.ScoringGroupList]);
|
this.validateType([RecordValueType.DelegateList]);
|
||||||
return this.value.map((delegate: any) => {
|
return (this as DelegateListRecordValue).value;
|
||||||
const delegateType = DelegateType[delegate.delegateType];
|
|
||||||
|
|
||||||
if (delegateType === undefined) {
|
|
||||||
throw new Error(
|
|
||||||
`${delegate.delegateType as string} is not a valid DelegateType.`
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
const delegationDateTime = new Date(delegate.delegationDateTime);
|
|
||||||
|
|
||||||
const hasName = delegate.name !== null && delegate.name !== undefined;
|
|
||||||
const name = hasName ? delegate.name : null;
|
|
||||||
|
|
||||||
const hasCompletionDate =
|
|
||||||
delegate.delegationCompletedDateTime !== null &&
|
|
||||||
delegate.delegationCompletedDateTime !== undefined;
|
|
||||||
|
|
||||||
const delegationCompletedDateTime = hasCompletionDate
|
|
||||||
? new Date(delegate.delegationCompletedDateTime)
|
|
||||||
: null;
|
|
||||||
|
|
||||||
return new Delegate(
|
|
||||||
delegate.delegateType,
|
|
||||||
name,
|
|
||||||
delegate.emailAddress,
|
|
||||||
delegationDateTime,
|
|
||||||
delegationCompletedDateTime
|
|
||||||
);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -170,70 +118,17 @@ export class RecordValue<T> {
|
|||||||
*/
|
*/
|
||||||
public asScoringGroupArray(): ScoringGroup[] {
|
public asScoringGroupArray(): ScoringGroup[] {
|
||||||
this.validateType([RecordValueType.ScoringGroupList]);
|
this.validateType([RecordValueType.ScoringGroupList]);
|
||||||
return this.value.map(
|
return (this as ScoringGroupListRecordValue).value;
|
||||||
(scoringGroup: any) =>
|
|
||||||
new ScoringGroup(
|
|
||||||
scoringGroup.listValueId,
|
|
||||||
scoringGroup.name,
|
|
||||||
scoringGroup.score,
|
|
||||||
scoringGroup.maximumScore
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @method asTimeSpanData - Gets the value as a TimeSpanData object.
|
* @method asTimeSpanData - Gets the value as a TimeSpanData object.
|
||||||
* @returns {TimeSpanData} - The value as a TimeSpanData object.
|
* @returns {TimeSpanData} - The value as a TimeSpanData object.
|
||||||
* @throws {Error} - If the value is not a TimeSpanData object.
|
* @throws {Error} - If the value is not a TimeSpanData object.
|
||||||
* @throws {Error} - If the increment is not valid.
|
|
||||||
* @throws {Error} - If the recurrence is not valid.
|
|
||||||
*/
|
*/
|
||||||
public asTimeSpanData(): TimeSpanData {
|
public asTimeSpanData(): TimeSpanData {
|
||||||
this.validateType([RecordValueType.TimeSpan]);
|
this.validateType([RecordValueType.TimeSpan]);
|
||||||
|
return (this as TimeSpanRecordValue).value;
|
||||||
const increment = TimeSpanIncrement[this.value.increment];
|
|
||||||
|
|
||||||
const hasRecurrence =
|
|
||||||
this.value.recurrence !== null && this.value.recurrence !== undefined;
|
|
||||||
|
|
||||||
const recurrene = hasRecurrence
|
|
||||||
? TimeSpanRecurrenceType[this.value.recurrence]
|
|
||||||
: null;
|
|
||||||
|
|
||||||
const hasEndAfterOccurrences =
|
|
||||||
this.value.endAfterOccurrences !== null &&
|
|
||||||
this.value.endAfterOccurrences !== undefined;
|
|
||||||
|
|
||||||
const endAfterOccurrences = hasEndAfterOccurrences
|
|
||||||
? this.value.endAfterOccurrences
|
|
||||||
: null;
|
|
||||||
|
|
||||||
const hasEndByDate =
|
|
||||||
this.value.endByDate !== null && this.value.endByDate !== undefined;
|
|
||||||
|
|
||||||
const endByDate = hasEndByDate ? new Date(this.value.endByDate) : null;
|
|
||||||
|
|
||||||
if (increment === undefined) {
|
|
||||||
throw new Error(
|
|
||||||
`${this.value.increment as string} is not a valid TimeSpanIncrement.`
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (recurrene === undefined) {
|
|
||||||
throw new Error(
|
|
||||||
`${
|
|
||||||
this.value.recurrence as string
|
|
||||||
} is not a valid TimeSpanRecurrenceType.`
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return new TimeSpanData(
|
|
||||||
this.value.quantity,
|
|
||||||
increment,
|
|
||||||
recurrene,
|
|
||||||
endAfterOccurrences,
|
|
||||||
endByDate
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -0,0 +1,9 @@
|
|||||||
|
import { RecordValueType } from '../enums/RecordValueType';
|
||||||
|
import { RecordValue } from './RecordValue';
|
||||||
|
import { type ScoringGroup } from './ScoringGroup';
|
||||||
|
|
||||||
|
export class ScoringGroupListRecordValue extends RecordValue<ScoringGroup[]> {
|
||||||
|
constructor(fieldId: number, value: ScoringGroup[]) {
|
||||||
|
super(RecordValueType.ScoringGroupList, fieldId, value);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
import { RecordValueType } from '../enums/RecordValueType';
|
||||||
|
import { RecordValue } from './RecordValue';
|
||||||
|
|
||||||
|
export class StringListRecordValue extends RecordValue<string[]> {
|
||||||
|
constructor(fieldId: number, value: string[]) {
|
||||||
|
super(RecordValueType.StringList, fieldId, value);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
import { RecordValueType } from '../enums/RecordValueType';
|
||||||
|
import { RecordValue } from './RecordValue';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @class StringRecordValue - A record value represented by a string.
|
||||||
|
*/
|
||||||
|
export class StringRecordValue extends RecordValue<string> {
|
||||||
|
/**
|
||||||
|
* @constructor - Creates a new instance of StringRecordValue.
|
||||||
|
* @param {number} fieldId - The id of the field.
|
||||||
|
* @param {string} value - The value of the field.
|
||||||
|
* @returns {StringRecordValue} - A new instance of StringRecordValue.
|
||||||
|
*/
|
||||||
|
constructor(fieldId: number, value: string) {
|
||||||
|
super(RecordValueType.String, fieldId, value);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
import { RecordValueType } from '../enums/RecordValueType';
|
||||||
|
import { RecordValue } from './RecordValue';
|
||||||
|
import { type TimeSpanData } from './TimeSpanData';
|
||||||
|
|
||||||
|
export class TimeSpanRecordValue extends RecordValue<TimeSpanData> {
|
||||||
|
constructor(fieldId: number, value: TimeSpanData) {
|
||||||
|
super(RecordValueType.TimeSpan, fieldId, value);
|
||||||
|
}
|
||||||
|
}
|
||||||
+520
-42
@@ -15,9 +15,6 @@ import { ReferenceField } from '../src/models/ReferenceField';
|
|||||||
import { Multiplicity } from '../src/enums/Multiplicity';
|
import { Multiplicity } from '../src/enums/Multiplicity';
|
||||||
import { ListField } from '../src/models/ListField';
|
import { ListField } from '../src/models/ListField';
|
||||||
import { File } from '../src/models/File';
|
import { File } from '../src/models/File';
|
||||||
import fs from 'fs';
|
|
||||||
import { type AxiosResponse } from 'axios';
|
|
||||||
import path from 'path';
|
|
||||||
import { ListItemResponse } from '../src/models/ListItemResponse';
|
import { ListItemResponse } from '../src/models/ListItemResponse';
|
||||||
import { GetPagedReportsResponse } from '../src/models/GetPagedReportsResponse';
|
import { GetPagedReportsResponse } from '../src/models/GetPagedReportsResponse';
|
||||||
import { Report } from '../src/models/Report';
|
import { Report } from '../src/models/Report';
|
||||||
@@ -26,6 +23,10 @@ import { Row } from '../src/models/Row';
|
|||||||
import { Record } from '../src/models/Record';
|
import { Record } from '../src/models/Record';
|
||||||
import { RecordValue } from '../src/models/RecordValue';
|
import { RecordValue } from '../src/models/RecordValue';
|
||||||
import { GetPagedRecordsResponse } from '../src/models/GetPagedRecordsResponse';
|
import { GetPagedRecordsResponse } from '../src/models/GetPagedRecordsResponse';
|
||||||
|
import { testFieldData } from './testData/testFieldData';
|
||||||
|
import { type AxiosResponse } from 'axios';
|
||||||
|
import path from 'path';
|
||||||
|
import fs from 'fs';
|
||||||
|
|
||||||
describe('ApiResponse', function () {
|
describe('ApiResponse', function () {
|
||||||
it('should be defined', function () {
|
it('should be defined', function () {
|
||||||
@@ -1142,36 +1143,172 @@ describe('ApiResponse', function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should return an ApiResponse<Record>', function () {
|
it('should return an ApiResponse<Record>', function () {
|
||||||
|
testFieldData.forEach((recordValue) => {
|
||||||
|
const mockResponseData = {
|
||||||
|
appId: 1,
|
||||||
|
recordId: 1,
|
||||||
|
fieldData: [recordValue],
|
||||||
|
};
|
||||||
|
|
||||||
|
const apiResponse = new ApiResponse(200, 'OK', mockResponseData);
|
||||||
|
const record = apiResponse.asRecordType();
|
||||||
|
|
||||||
|
expect(record).to.be.an.instanceof(ApiResponse<Record>);
|
||||||
|
expect(record.data).to.be.an.instanceof(Record);
|
||||||
|
expect(record.data).to.have.property('appId', 1);
|
||||||
|
expect(record.data).to.have.property('recordId', 1);
|
||||||
|
expect(record.data).to.have.property('fieldData').that.is.an('array');
|
||||||
|
expect(record.data).to.not.be.null;
|
||||||
|
|
||||||
|
if (record.data != null) {
|
||||||
|
record.data.fieldData.forEach((recordValue) => {
|
||||||
|
expect(recordValue).to.be.an.instanceof(RecordValue);
|
||||||
|
expect(recordValue).to.have.property('type');
|
||||||
|
expect(recordValue).to.have.property('fieldId');
|
||||||
|
expect(recordValue).to.have.property('value');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should throw an error if a record value contains an unknown type', function () {
|
||||||
const mockResponseData = {
|
const mockResponseData = {
|
||||||
appId: 1,
|
appId: 1,
|
||||||
recordId: 1,
|
recordId: 1,
|
||||||
fieldData: [
|
fieldData: [
|
||||||
{
|
{
|
||||||
type: 'Text',
|
type: 'Unknown',
|
||||||
fieldId: 'field 1',
|
fieldId: 1,
|
||||||
value: 'field value 1',
|
value: 'value',
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
|
|
||||||
const apiResponse = new ApiResponse(200, 'OK', mockResponseData);
|
const apiResponse = new ApiResponse(200, 'OK', mockResponseData);
|
||||||
const record = apiResponse.asRecordType();
|
|
||||||
|
|
||||||
expect(record).to.be.an.instanceof(ApiResponse<Record>);
|
expect(() => {
|
||||||
expect(record.data).to.be.an.instanceof(Record);
|
apiResponse.asRecordType();
|
||||||
expect(record.data).to.have.property('appId', 1);
|
}).to.throw();
|
||||||
expect(record.data).to.have.property('recordId', 1);
|
});
|
||||||
expect(record.data).to.have.property('fieldData').that.is.an('array');
|
|
||||||
expect(record.data).to.not.be.null;
|
|
||||||
|
|
||||||
if (record.data != null) {
|
it('should throw an error if a record value for a survey delegate field contains an unknown delegate type', function () {
|
||||||
record.data.fieldData.forEach((recordValue) => {
|
const mockResponseData = {
|
||||||
expect(recordValue).to.be.an.instanceof(RecordValue);
|
appId: 1,
|
||||||
expect(recordValue).to.have.property('type');
|
recordId: 1,
|
||||||
expect(recordValue).to.have.property('fieldId');
|
fieldData: [
|
||||||
expect(recordValue).to.have.property('value');
|
{
|
||||||
});
|
type: 'ScoringGroupList',
|
||||||
}
|
fieldId: 12167,
|
||||||
|
value: [
|
||||||
|
{
|
||||||
|
delegateType: 'Unknown',
|
||||||
|
name: 'test_delegate',
|
||||||
|
emailAddress: 'test@test.com',
|
||||||
|
delegationType: 'AllPages',
|
||||||
|
pageIds: [],
|
||||||
|
answeredPageIds: [],
|
||||||
|
canReadOtherPages: false,
|
||||||
|
delegationDateTime: '2023-01-17T05:52:53.781Z',
|
||||||
|
delegationCompletedDateTime: '2023-01-17T05:53:12.617Z',
|
||||||
|
status: 'Pending',
|
||||||
|
isDeleted: false,
|
||||||
|
messagingDisplayText:
|
||||||
|
'Delegate Name: test_delegate -- Delegate Completed On: 1/17/2023 5:53 AM',
|
||||||
|
guid: '00000000-0000-0000-0000-000000000000',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
};
|
||||||
|
|
||||||
|
const apiResponse = new ApiResponse(200, 'OK', mockResponseData);
|
||||||
|
|
||||||
|
expect(() => {
|
||||||
|
apiResponse.asRecordType();
|
||||||
|
}).to.throw();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should throw an error if record value for an attachment field contains an unknown file storage site type', function () {
|
||||||
|
const mockResponseData = {
|
||||||
|
appId: 1,
|
||||||
|
recordId: 1,
|
||||||
|
fieldData: [
|
||||||
|
{
|
||||||
|
type: 'AttachmentList',
|
||||||
|
fieldId: 12888,
|
||||||
|
value: [
|
||||||
|
{
|
||||||
|
fileId: 1348,
|
||||||
|
fileName: 'onspring-api-playground.py',
|
||||||
|
notes: '',
|
||||||
|
storageLocation: 'Unknown',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
fileId: 1349,
|
||||||
|
fileName: 'core_isolation_warning.png',
|
||||||
|
notes: '',
|
||||||
|
storageLocation: 'Internal',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
};
|
||||||
|
|
||||||
|
const apiResponse = new ApiResponse(200, 'OK', mockResponseData);
|
||||||
|
|
||||||
|
expect(() => {
|
||||||
|
apiResponse.asRecordType();
|
||||||
|
}).to.throw();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should throw an error if record value for a timespan field contains an unknown increment type', function () {
|
||||||
|
const mockResponseData = {
|
||||||
|
appId: 1,
|
||||||
|
recordId: 1,
|
||||||
|
fieldData: [
|
||||||
|
{
|
||||||
|
type: 'TimeSpan',
|
||||||
|
fieldId: 12893,
|
||||||
|
value: {
|
||||||
|
quantity: 10,
|
||||||
|
increment: 'Unknown',
|
||||||
|
recurrence: 'EndByDate',
|
||||||
|
endByDate: '2023-02-16T06:00:00Z',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
};
|
||||||
|
|
||||||
|
const apiResponse = new ApiResponse(200, 'OK', mockResponseData);
|
||||||
|
|
||||||
|
expect(() => {
|
||||||
|
apiResponse.asRecordType();
|
||||||
|
}).to.throw();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should throw an error if record value for a timespan field contains an unknown recurrence type', function () {
|
||||||
|
const mockResponseData = {
|
||||||
|
appId: 1,
|
||||||
|
recordId: 1,
|
||||||
|
fieldData: [
|
||||||
|
{
|
||||||
|
type: 'TimeSpan',
|
||||||
|
fieldId: 12893,
|
||||||
|
value: {
|
||||||
|
quantity: 10,
|
||||||
|
increment: 'Days',
|
||||||
|
recurrence: 'Unknown',
|
||||||
|
endByDate: '2023-02-16T06:00:00Z',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
};
|
||||||
|
|
||||||
|
const apiResponse = new ApiResponse(200, 'OK', mockResponseData);
|
||||||
|
|
||||||
|
expect(() => {
|
||||||
|
apiResponse.asRecordType();
|
||||||
|
}).to.throw();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -1203,24 +1340,12 @@ describe('ApiResponse', function () {
|
|||||||
{
|
{
|
||||||
appId: 1,
|
appId: 1,
|
||||||
recordId: 1,
|
recordId: 1,
|
||||||
fieldData: [
|
fieldData: testFieldData,
|
||||||
{
|
|
||||||
type: 'Text',
|
|
||||||
fieldId: 'field 1',
|
|
||||||
value: 'field value 1',
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
appId: 2,
|
appId: 2,
|
||||||
recordId: 2,
|
recordId: 2,
|
||||||
fieldData: [
|
fieldData: testFieldData,
|
||||||
{
|
|
||||||
type: 'Text',
|
|
||||||
fieldId: 'field 1',
|
|
||||||
value: 'field value 1',
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
@@ -1250,9 +1375,203 @@ describe('ApiResponse', function () {
|
|||||||
if (getPagedRecordsResponse.data != null) {
|
if (getPagedRecordsResponse.data != null) {
|
||||||
getPagedRecordsResponse.data.items.forEach((record) => {
|
getPagedRecordsResponse.data.items.forEach((record) => {
|
||||||
expect(record).to.be.an.instanceof(Record);
|
expect(record).to.be.an.instanceof(Record);
|
||||||
|
|
||||||
|
expect(record).to.have.property('appId');
|
||||||
|
expect(record).to.have.property('recordId');
|
||||||
|
expect(record).to.have.property('fieldData').that.is.an('array');
|
||||||
|
expect(record).to.not.be.null;
|
||||||
|
|
||||||
|
if (record != null) {
|
||||||
|
record.fieldData.forEach((recordValue) => {
|
||||||
|
expect(recordValue).to.be.an.instanceof(RecordValue);
|
||||||
|
expect(recordValue).to.have.property('type');
|
||||||
|
expect(recordValue).to.have.property('fieldId');
|
||||||
|
expect(recordValue).to.have.property('value');
|
||||||
|
});
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should throw an error if a record value contains an unknown type', function () {
|
||||||
|
const mockResponseData = {
|
||||||
|
pageSize: 1,
|
||||||
|
pageNumber: 1,
|
||||||
|
totalRecords: 1,
|
||||||
|
totalPages: 1,
|
||||||
|
items: [
|
||||||
|
{
|
||||||
|
appId: 1,
|
||||||
|
recordId: 1,
|
||||||
|
fieldData: [
|
||||||
|
{
|
||||||
|
type: 'Unknown',
|
||||||
|
fieldId: 1,
|
||||||
|
value: 'value',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
};
|
||||||
|
|
||||||
|
const apiResponse = new ApiResponse(200, 'OK', mockResponseData);
|
||||||
|
|
||||||
|
expect(() => {
|
||||||
|
apiResponse.asGetPagedRecordsResponseType();
|
||||||
|
}).to.throw();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should throw an error if a record value for a survey delegate field contains an unknown delegate type', function () {
|
||||||
|
const mockResponseData = {
|
||||||
|
pageSize: 1,
|
||||||
|
pageNumber: 1,
|
||||||
|
totalRecords: 1,
|
||||||
|
totalPages: 1,
|
||||||
|
items: [
|
||||||
|
{
|
||||||
|
appId: 1,
|
||||||
|
recordId: 1,
|
||||||
|
fieldData: [
|
||||||
|
{
|
||||||
|
type: 'ScoringGroupList',
|
||||||
|
fieldId: 12167,
|
||||||
|
value: [
|
||||||
|
{
|
||||||
|
delegateType: 'Unknown',
|
||||||
|
name: 'test_delegate',
|
||||||
|
emailAddress: 'test@test.com',
|
||||||
|
delegationType: 'AllPages',
|
||||||
|
pageIds: [],
|
||||||
|
answeredPageIds: [],
|
||||||
|
canReadOtherPages: false,
|
||||||
|
delegationDateTime: '2023-01-17T05:52:53.781Z',
|
||||||
|
delegationCompletedDateTime: '2023-01-17T05:53:12.617Z',
|
||||||
|
status: 'Pending',
|
||||||
|
isDeleted: false,
|
||||||
|
messagingDisplayText:
|
||||||
|
'Delegate Name: test_delegate -- Delegate Completed On: 1/17/2023 5:53 AM',
|
||||||
|
guid: '00000000-0000-0000-0000-000000000000',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
};
|
||||||
|
|
||||||
|
const apiResponse = new ApiResponse(200, 'OK', mockResponseData);
|
||||||
|
|
||||||
|
expect(() => {
|
||||||
|
apiResponse.asGetPagedRecordsResponseType();
|
||||||
|
}).to.throw();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should throw an error if record value for an attachment field contains an unknown file storage site type', function () {
|
||||||
|
const mockResponseData = {
|
||||||
|
pageSize: 1,
|
||||||
|
pageNumber: 1,
|
||||||
|
totalRecords: 1,
|
||||||
|
totalPages: 1,
|
||||||
|
items: [
|
||||||
|
{
|
||||||
|
appId: 1,
|
||||||
|
recordId: 1,
|
||||||
|
fieldData: [
|
||||||
|
{
|
||||||
|
type: 'AttachmentList',
|
||||||
|
fieldId: 12888,
|
||||||
|
value: [
|
||||||
|
{
|
||||||
|
fileId: 1348,
|
||||||
|
fileName: 'onspring-api-playground.py',
|
||||||
|
notes: '',
|
||||||
|
storageLocation: 'Unknown',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
fileId: 1349,
|
||||||
|
fileName: 'core_isolation_warning.png',
|
||||||
|
notes: '',
|
||||||
|
storageLocation: 'Internal',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
};
|
||||||
|
|
||||||
|
const apiResponse = new ApiResponse(200, 'OK', mockResponseData);
|
||||||
|
|
||||||
|
expect(() => {
|
||||||
|
apiResponse.asGetPagedRecordsResponseType();
|
||||||
|
}).to.throw();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should throw an error if record value for a timespan field contains an unknown increment type', function () {
|
||||||
|
const mockResponseData = {
|
||||||
|
pageSize: 1,
|
||||||
|
pageNumber: 1,
|
||||||
|
totalRecords: 1,
|
||||||
|
totalPages: 1,
|
||||||
|
items: [
|
||||||
|
{
|
||||||
|
appId: 1,
|
||||||
|
recordId: 1,
|
||||||
|
fieldData: [
|
||||||
|
{
|
||||||
|
type: 'TimeSpan',
|
||||||
|
fieldId: 12893,
|
||||||
|
value: {
|
||||||
|
quantity: 10,
|
||||||
|
increment: 'Unknown',
|
||||||
|
recurrence: 'EndByDate',
|
||||||
|
endByDate: '2023-02-16T06:00:00Z',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
};
|
||||||
|
|
||||||
|
const apiResponse = new ApiResponse(200, 'OK', mockResponseData);
|
||||||
|
|
||||||
|
expect(() => {
|
||||||
|
apiResponse.asGetPagedRecordsResponseType();
|
||||||
|
}).to.throw();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should throw an error if record value for a timespan field contains an unknown recurrence type', function () {
|
||||||
|
const mockResponseData = {
|
||||||
|
pageSize: 1,
|
||||||
|
pageNumber: 1,
|
||||||
|
totalRecords: 1,
|
||||||
|
totalPages: 1,
|
||||||
|
items: [
|
||||||
|
{
|
||||||
|
appId: 1,
|
||||||
|
recordId: 1,
|
||||||
|
fieldData: [
|
||||||
|
{
|
||||||
|
type: 'TimeSpan',
|
||||||
|
fieldId: 12893,
|
||||||
|
value: {
|
||||||
|
quantity: 10,
|
||||||
|
increment: 'Days',
|
||||||
|
recurrence: 'Unknown',
|
||||||
|
endByDate: '2023-02-16T06:00:00Z',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
};
|
||||||
|
|
||||||
|
const apiResponse = new ApiResponse(200, 'OK', mockResponseData);
|
||||||
|
|
||||||
|
expect(() => {
|
||||||
|
apiResponse.asGetPagedRecordsResponseType();
|
||||||
|
}).to.throw();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('asRecordCollectionType', function () {
|
describe('asRecordCollectionType', function () {
|
||||||
@@ -1275,13 +1594,7 @@ describe('ApiResponse', function () {
|
|||||||
{
|
{
|
||||||
appId: 1,
|
appId: 1,
|
||||||
recordId: 1,
|
recordId: 1,
|
||||||
fieldData: [
|
fieldData: testFieldData,
|
||||||
{
|
|
||||||
type: 'Text',
|
|
||||||
fieldId: 'field 1',
|
|
||||||
value: 'field value 1',
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
@@ -1322,5 +1635,170 @@ describe('ApiResponse', function () {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should throw an error if a record value contains an unknown type', function () {
|
||||||
|
const mockResponseData = {
|
||||||
|
count: 1,
|
||||||
|
items: [
|
||||||
|
{
|
||||||
|
appId: 1,
|
||||||
|
recordId: 1,
|
||||||
|
fieldData: [
|
||||||
|
{
|
||||||
|
type: 'Unknown',
|
||||||
|
fieldId: 1,
|
||||||
|
value: 'value',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
};
|
||||||
|
|
||||||
|
const apiResponse = new ApiResponse(200, 'OK', mockResponseData);
|
||||||
|
|
||||||
|
expect(() => {
|
||||||
|
apiResponse.asRecordCollectionType();
|
||||||
|
}).to.throw();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should throw an error if a record value for a survey delegate field contains an unknown delegate type', function () {
|
||||||
|
const mockResponseData = {
|
||||||
|
count: 1,
|
||||||
|
items: [
|
||||||
|
{
|
||||||
|
appId: 1,
|
||||||
|
recordId: 1,
|
||||||
|
fieldData: [
|
||||||
|
{
|
||||||
|
type: 'ScoringGroupList',
|
||||||
|
fieldId: 12167,
|
||||||
|
value: [
|
||||||
|
{
|
||||||
|
delegateType: 'Unknown',
|
||||||
|
name: 'test_delegate',
|
||||||
|
emailAddress: 'test@test.com',
|
||||||
|
delegationType: 'AllPages',
|
||||||
|
pageIds: [],
|
||||||
|
answeredPageIds: [],
|
||||||
|
canReadOtherPages: false,
|
||||||
|
delegationDateTime: '2023-01-17T05:52:53.781Z',
|
||||||
|
delegationCompletedDateTime: '2023-01-17T05:53:12.617Z',
|
||||||
|
status: 'Pending',
|
||||||
|
isDeleted: false,
|
||||||
|
messagingDisplayText:
|
||||||
|
'Delegate Name: test_delegate -- Delegate Completed On: 1/17/2023 5:53 AM',
|
||||||
|
guid: '00000000-0000-0000-0000-000000000000',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
};
|
||||||
|
|
||||||
|
const apiResponse = new ApiResponse(200, 'OK', mockResponseData);
|
||||||
|
|
||||||
|
expect(() => {
|
||||||
|
apiResponse.asRecordCollectionType();
|
||||||
|
}).to.throw();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should throw an error if record value for an attachment field contains an unknown file storage site type', function () {
|
||||||
|
const mockResponseData = {
|
||||||
|
count: 1,
|
||||||
|
items: [
|
||||||
|
{
|
||||||
|
appId: 1,
|
||||||
|
recordId: 1,
|
||||||
|
fieldData: [
|
||||||
|
{
|
||||||
|
type: 'AttachmentList',
|
||||||
|
fieldId: 12888,
|
||||||
|
value: [
|
||||||
|
{
|
||||||
|
fileId: 1348,
|
||||||
|
fileName: 'onspring-api-playground.py',
|
||||||
|
notes: '',
|
||||||
|
storageLocation: 'Unknown',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
fileId: 1349,
|
||||||
|
fileName: 'core_isolation_warning.png',
|
||||||
|
notes: '',
|
||||||
|
storageLocation: 'Internal',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
};
|
||||||
|
|
||||||
|
const apiResponse = new ApiResponse(200, 'OK', mockResponseData);
|
||||||
|
|
||||||
|
expect(() => {
|
||||||
|
apiResponse.asRecordCollectionType();
|
||||||
|
}).to.throw();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should throw an error if record value for a timespan field contains an unknown increment type', function () {
|
||||||
|
const mockResponseData = {
|
||||||
|
count: 1,
|
||||||
|
items: [
|
||||||
|
{
|
||||||
|
appId: 1,
|
||||||
|
recordId: 1,
|
||||||
|
fieldData: [
|
||||||
|
{
|
||||||
|
type: 'TimeSpan',
|
||||||
|
fieldId: 12893,
|
||||||
|
value: {
|
||||||
|
quantity: 10,
|
||||||
|
increment: 'Unknown',
|
||||||
|
recurrence: 'EndByDate',
|
||||||
|
endByDate: '2023-02-16T06:00:00Z',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
};
|
||||||
|
|
||||||
|
const apiResponse = new ApiResponse(200, 'OK', mockResponseData);
|
||||||
|
|
||||||
|
expect(() => {
|
||||||
|
apiResponse.asRecordCollectionType();
|
||||||
|
}).to.throw();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should throw an error if record value for a timespan field contains an unknown recurrence type', function () {
|
||||||
|
const mockResponseData = {
|
||||||
|
count: 1,
|
||||||
|
items: [
|
||||||
|
{
|
||||||
|
appId: 1,
|
||||||
|
recordId: 1,
|
||||||
|
fieldData: [
|
||||||
|
{
|
||||||
|
type: 'TimeSpan',
|
||||||
|
fieldId: 12893,
|
||||||
|
value: {
|
||||||
|
quantity: 10,
|
||||||
|
increment: 'Days',
|
||||||
|
recurrence: 'Unknown',
|
||||||
|
endByDate: '2023-02-16T06:00:00Z',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
};
|
||||||
|
|
||||||
|
const apiResponse = new ApiResponse(200, 'OK', mockResponseData);
|
||||||
|
|
||||||
|
expect(() => {
|
||||||
|
apiResponse.asRecordCollectionType();
|
||||||
|
}).to.throw();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -0,0 +1,30 @@
|
|||||||
|
import { AttachmentListRecordValue } from '../src/models/AttachmentListRecordValue';
|
||||||
|
import { expect } from 'chai';
|
||||||
|
|
||||||
|
describe('AttachmentListRecordValue', function () {
|
||||||
|
it('should be defined', function () {
|
||||||
|
expect(AttachmentListRecordValue).to.not.be.undefined;
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should have a constructor', function () {
|
||||||
|
expect(AttachmentListRecordValue).to.have.property('constructor');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should hav a constructor that takes a fieldId and value', function () {
|
||||||
|
expect(AttachmentListRecordValue).to.have.lengthOf(2);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should have fieldId, value, and type properties', function () {
|
||||||
|
const attachmentListRecordValue = new AttachmentListRecordValue(1, []);
|
||||||
|
expect(attachmentListRecordValue).to.have.property('fieldId');
|
||||||
|
expect(attachmentListRecordValue).to.have.property('value');
|
||||||
|
expect(attachmentListRecordValue).to.have.property('type');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should have a constructor that sets its properties correctly', function () {
|
||||||
|
const attachmentListRecordValue = new AttachmentListRecordValue(1, []);
|
||||||
|
expect(attachmentListRecordValue.fieldId).to.equal(1);
|
||||||
|
expect(attachmentListRecordValue.value).to.deep.equal([]);
|
||||||
|
expect(attachmentListRecordValue.type).to.equal('AttachmentList');
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
import { DateRecordValue } from '../src/models/DateRecordValue';
|
||||||
|
import { expect } from 'chai';
|
||||||
|
|
||||||
|
describe('DateRecordValue', function () {
|
||||||
|
it('should be defined', function () {
|
||||||
|
expect(DateRecordValue).to.not.be.undefined;
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should have a constructor', function () {
|
||||||
|
expect(DateRecordValue).to.have.property('constructor');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should hav a constructor that takes a fieldId and value', function () {
|
||||||
|
expect(DateRecordValue).to.have.lengthOf(2);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should have fieldId, value, and type properties', function () {
|
||||||
|
const dateRecordValue = new DateRecordValue(1, new Date());
|
||||||
|
expect(dateRecordValue).to.have.property('fieldId');
|
||||||
|
expect(dateRecordValue).to.have.property('value');
|
||||||
|
expect(dateRecordValue).to.have.property('type');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should have a constructor that sets its properties correctly', function () {
|
||||||
|
const date = new Date();
|
||||||
|
const dateRecordValue = new DateRecordValue(1, date);
|
||||||
|
expect(dateRecordValue.fieldId).to.equal(1);
|
||||||
|
expect(dateRecordValue.value).to.deep.equal(date);
|
||||||
|
expect(dateRecordValue.type).to.equal('Date');
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
import { DecimalRecordValue } from '../src/models/DecimalRecordValue';
|
||||||
|
import { expect } from 'chai';
|
||||||
|
|
||||||
|
describe('DecimalRecordValue', function () {
|
||||||
|
it('should be defined', function () {
|
||||||
|
expect(DecimalRecordValue).to.not.be.undefined;
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should have a constructor', function () {
|
||||||
|
expect(DecimalRecordValue).to.have.property('constructor');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should hav a constructor that takes a fieldId and value', function () {
|
||||||
|
expect(DecimalRecordValue).to.have.lengthOf(2);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should have fieldId, value, and type properties', function () {
|
||||||
|
const decimalRecordValue = new DecimalRecordValue(1, 1);
|
||||||
|
expect(decimalRecordValue).to.have.property('fieldId');
|
||||||
|
expect(decimalRecordValue).to.have.property('value');
|
||||||
|
expect(decimalRecordValue).to.have.property('type');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should have a constructor that sets its properties correctly', function () {
|
||||||
|
const decimalRecordValue = new DecimalRecordValue(1, 1);
|
||||||
|
expect(decimalRecordValue.fieldId).to.equal(1);
|
||||||
|
expect(decimalRecordValue.value).to.deep.equal(1);
|
||||||
|
expect(decimalRecordValue.type).to.equal('Decimal');
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
import { DelegateListRecordValue } from '../src/models/DelegateListRecordValue';
|
||||||
|
import { expect } from 'chai';
|
||||||
|
|
||||||
|
describe('DelegateListRecordValue', function () {
|
||||||
|
it('should be defined', function () {
|
||||||
|
expect(DelegateListRecordValue).to.not.be.undefined;
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should have a constructor', function () {
|
||||||
|
expect(DelegateListRecordValue).to.have.property('constructor');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should hav a constructor that takes a fieldId and value', function () {
|
||||||
|
expect(DelegateListRecordValue).to.have.lengthOf(2);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should have fieldId, value, and type properties', function () {
|
||||||
|
const delegateListRecordValue = new DelegateListRecordValue(1, []);
|
||||||
|
expect(delegateListRecordValue).to.have.property('fieldId');
|
||||||
|
expect(delegateListRecordValue).to.have.property('value');
|
||||||
|
expect(delegateListRecordValue).to.have.property('type');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should have a constructor that sets its properties correctly', function () {
|
||||||
|
const delegateListRecordValue = new DelegateListRecordValue(1, []);
|
||||||
|
expect(delegateListRecordValue.fieldId).to.equal(1);
|
||||||
|
expect(delegateListRecordValue.value).to.deep.equal([]);
|
||||||
|
expect(delegateListRecordValue.type).to.equal('DelegateList');
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
import { FileListRecordValue } from '../src/models/FileListRecordValue';
|
||||||
|
import { expect } from 'chai';
|
||||||
|
|
||||||
|
describe('FileListRecordValue', function () {
|
||||||
|
it('should be defined', function () {
|
||||||
|
expect(FileListRecordValue).to.not.be.undefined;
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should have a constructor', function () {
|
||||||
|
expect(FileListRecordValue).to.have.property('constructor');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should hav a constructor that takes a fieldId and value', function () {
|
||||||
|
expect(FileListRecordValue).to.have.lengthOf(2);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should have fieldId, value, and type properties', function () {
|
||||||
|
const fileListRecordValue = new FileListRecordValue(1, []);
|
||||||
|
expect(fileListRecordValue).to.have.property('fieldId');
|
||||||
|
expect(fileListRecordValue).to.have.property('value');
|
||||||
|
expect(fileListRecordValue).to.have.property('type');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should have a constructor that sets its properties correctly', function () {
|
||||||
|
const fileListRecordValue = new FileListRecordValue(1, []);
|
||||||
|
expect(fileListRecordValue.fieldId).to.equal(1);
|
||||||
|
expect(fileListRecordValue.value).to.deep.equal([]);
|
||||||
|
expect(fileListRecordValue.type).to.equal('FileList');
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
import { GuidListRecordValue } from '../src/models/GuidListRecordValue';
|
||||||
|
import { expect } from 'chai';
|
||||||
|
|
||||||
|
describe('GuidListRecordValue', function () {
|
||||||
|
it('should be defined', function () {
|
||||||
|
expect(GuidListRecordValue).to.not.be.undefined;
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should have a constructor', function () {
|
||||||
|
expect(GuidListRecordValue).to.have.property('constructor');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should hav a constructor that takes a fieldId and value', function () {
|
||||||
|
expect(GuidListRecordValue).to.have.lengthOf(2);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should have fieldId, value, and type properties', function () {
|
||||||
|
const guidListRecordValue = new GuidListRecordValue(1, []);
|
||||||
|
expect(guidListRecordValue).to.have.property('fieldId');
|
||||||
|
expect(guidListRecordValue).to.have.property('value');
|
||||||
|
expect(guidListRecordValue).to.have.property('type');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should have a constructor that sets its properties correctly', function () {
|
||||||
|
const guidListRecordValue = new GuidListRecordValue(1, []);
|
||||||
|
expect(guidListRecordValue.fieldId).to.equal(1);
|
||||||
|
expect(guidListRecordValue.value).to.deep.equal([]);
|
||||||
|
expect(guidListRecordValue.type).to.equal('GuidList');
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
import { GuidRecordValue } from '../src/models/GuidRecordValue';
|
||||||
|
import { expect } from 'chai';
|
||||||
|
|
||||||
|
describe('GuidRecordValue', function () {
|
||||||
|
it('should be defined', function () {
|
||||||
|
expect(GuidRecordValue).to.not.be.undefined;
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should have a constructor', function () {
|
||||||
|
expect(GuidRecordValue).to.have.property('constructor');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should hav a constructor that takes a fieldId and value', function () {
|
||||||
|
expect(GuidRecordValue).to.have.lengthOf(2);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should have fieldId, value, and type properties', function () {
|
||||||
|
const guidRecordValue = new GuidRecordValue(1, 'test');
|
||||||
|
expect(guidRecordValue).to.have.property('fieldId');
|
||||||
|
expect(guidRecordValue).to.have.property('value');
|
||||||
|
expect(guidRecordValue).to.have.property('type');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should have a constructor that sets its properties correctly', function () {
|
||||||
|
const guidRecordValue = new GuidRecordValue(1, 'test');
|
||||||
|
expect(guidRecordValue.fieldId).to.equal(1);
|
||||||
|
expect(guidRecordValue.value).to.deep.equal('test');
|
||||||
|
expect(guidRecordValue.type).to.equal('Guid');
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
import { IntegerListRecordValue } from '../src/models/IntegerListRecordValue';
|
||||||
|
import { expect } from 'chai';
|
||||||
|
|
||||||
|
describe('IntegerListRecordValue', function () {
|
||||||
|
it('should be defined', function () {
|
||||||
|
expect(IntegerListRecordValue).to.not.be.undefined;
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should have a constructor', function () {
|
||||||
|
expect(IntegerListRecordValue).to.have.property('constructor');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should hav a constructor that takes a fieldId and value', function () {
|
||||||
|
expect(IntegerListRecordValue).to.have.lengthOf(2);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should have fieldId, value, and type properties', function () {
|
||||||
|
const integerListRecordValue = new IntegerListRecordValue(1, []);
|
||||||
|
expect(integerListRecordValue).to.have.property('fieldId');
|
||||||
|
expect(integerListRecordValue).to.have.property('value');
|
||||||
|
expect(integerListRecordValue).to.have.property('type');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should have a constructor that sets its properties correctly', function () {
|
||||||
|
const integerListRecordValue = new IntegerListRecordValue(1, []);
|
||||||
|
expect(integerListRecordValue.fieldId).to.equal(1);
|
||||||
|
expect(integerListRecordValue.value).to.deep.equal([]);
|
||||||
|
expect(integerListRecordValue.type).to.equal('IntegerList');
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
import { IntegerRecordValue } from '../src/models/IntegerRecordValue';
|
||||||
|
import { expect } from 'chai';
|
||||||
|
|
||||||
|
describe('IntegerRecordValue', function () {
|
||||||
|
it('should be defined', function () {
|
||||||
|
expect(IntegerRecordValue).to.not.be.undefined;
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should have a constructor', function () {
|
||||||
|
expect(IntegerRecordValue).to.have.property('constructor');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should hav a constructor that takes a fieldId and value', function () {
|
||||||
|
expect(IntegerRecordValue).to.have.lengthOf(2);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should have fieldId, value, and type properties', function () {
|
||||||
|
const integerRecordValue = new IntegerRecordValue(1, 1);
|
||||||
|
expect(integerRecordValue).to.have.property('fieldId');
|
||||||
|
expect(integerRecordValue).to.have.property('value');
|
||||||
|
expect(integerRecordValue).to.have.property('type');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should have a constructor that sets its properties correctly', function () {
|
||||||
|
const integerRecordValue = new IntegerRecordValue(1, 1);
|
||||||
|
expect(integerRecordValue.fieldId).to.equal(1);
|
||||||
|
expect(integerRecordValue.value).to.deep.equal(1);
|
||||||
|
expect(integerRecordValue.type).to.equal('Integer');
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -2867,12 +2867,12 @@ describe('OnspringClient', function () {
|
|||||||
recordId: 1,
|
recordId: 1,
|
||||||
fieldData: [
|
fieldData: [
|
||||||
{
|
{
|
||||||
type: 'Text',
|
type: 'String',
|
||||||
fieldId: 1,
|
fieldId: 1,
|
||||||
value: 'Test',
|
value: 'Test',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
type: 'Text',
|
type: 'String',
|
||||||
fieldId: 2,
|
fieldId: 2,
|
||||||
value: 'Test',
|
value: 'Test',
|
||||||
},
|
},
|
||||||
@@ -3047,12 +3047,12 @@ describe('OnspringClient', function () {
|
|||||||
recordId: 1,
|
recordId: 1,
|
||||||
fieldData: [
|
fieldData: [
|
||||||
{
|
{
|
||||||
type: 'Text',
|
type: 'String',
|
||||||
fieldId: 1,
|
fieldId: 1,
|
||||||
value: 'Test',
|
value: 'Test',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
type: 'Text',
|
type: 'String',
|
||||||
fieldId: 2,
|
fieldId: 2,
|
||||||
value: 'Test',
|
value: 'Test',
|
||||||
},
|
},
|
||||||
@@ -3250,12 +3250,12 @@ describe('OnspringClient', function () {
|
|||||||
recordId: 1,
|
recordId: 1,
|
||||||
fieldData: [
|
fieldData: [
|
||||||
{
|
{
|
||||||
type: 'text',
|
type: 'String',
|
||||||
fieldId: 1,
|
fieldId: 1,
|
||||||
value: 'Test',
|
value: 'Test',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
type: 'text',
|
type: 'String',
|
||||||
fieldId: 2,
|
fieldId: 2,
|
||||||
value: 'Test',
|
value: 'Test',
|
||||||
},
|
},
|
||||||
@@ -3450,12 +3450,12 @@ describe('OnspringClient', function () {
|
|||||||
recordId: 1,
|
recordId: 1,
|
||||||
fieldData: [
|
fieldData: [
|
||||||
{
|
{
|
||||||
type: 'text',
|
type: 'String',
|
||||||
fieldId: 1,
|
fieldId: 1,
|
||||||
value: 'value',
|
value: 'value',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
type: 'text',
|
type: 'String',
|
||||||
fieldId: 2,
|
fieldId: 2,
|
||||||
value: 'value',
|
value: 'value',
|
||||||
},
|
},
|
||||||
|
|||||||
+47
-132
@@ -5,6 +5,10 @@ import { Attachment } from '../src/models/Attachment';
|
|||||||
import { Delegate } from '../src/models/Delegate';
|
import { Delegate } from '../src/models/Delegate';
|
||||||
import { ScoringGroup } from '../src/models/ScoringGroup';
|
import { ScoringGroup } from '../src/models/ScoringGroup';
|
||||||
import { TimeSpanData } from '../src/models/TimeSpanData';
|
import { TimeSpanData } from '../src/models/TimeSpanData';
|
||||||
|
import { FileStorageSite } from '../src/enums/FileStorageSite';
|
||||||
|
import { DelegateType } from '../src/enums/DelegateType';
|
||||||
|
import { TimeSpanRecurrenceType } from '../src/enums/TimeSpanRecurrenceType';
|
||||||
|
import { TimeSpanIncrement } from '../src/enums/TimeSpanIncrement';
|
||||||
|
|
||||||
describe('RecordValue', function () {
|
describe('RecordValue', function () {
|
||||||
it('should be defined', function () {
|
it('should be defined', function () {
|
||||||
@@ -112,9 +116,9 @@ describe('RecordValue', function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should return the value as a date for valid type', function () {
|
it('should return the value as a date for valid type', function () {
|
||||||
const value = new Date().toUTCString();
|
const value = new Date();
|
||||||
expect(new RecordValue(RecordValueType.Date, 2, value).asDate())
|
expect(new RecordValue(RecordValueType.Date, 2, value).asDate())
|
||||||
.to.deep.equal(new Date(value))
|
.to.deep.equal(value)
|
||||||
.and.to.be.a('date');
|
.and.to.be.a('date');
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -136,23 +140,9 @@ describe('RecordValue', function () {
|
|||||||
|
|
||||||
it('should return the value as an array of attachments for valid type', function () {
|
it('should return the value as an array of attachments for valid type', function () {
|
||||||
const value = [
|
const value = [
|
||||||
{
|
new Attachment(1, 'test', 'test', FileStorageSite.Internal),
|
||||||
fileId: 1,
|
new Attachment(1, 'test', 'test', FileStorageSite.Internal),
|
||||||
fileName: 'test',
|
new Attachment(1, 'test', null, FileStorageSite.Internal),
|
||||||
notes: 'test',
|
|
||||||
storageLocation: 'Internal',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
fileId: 1,
|
|
||||||
fileName: 'test',
|
|
||||||
storageLocation: 'Internal',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
fileId: 1,
|
|
||||||
fileName: 'test',
|
|
||||||
notes: null,
|
|
||||||
storageLocation: 'Internal',
|
|
||||||
},
|
|
||||||
];
|
];
|
||||||
|
|
||||||
const attachmentArray = new RecordValue(
|
const attachmentArray = new RecordValue(
|
||||||
@@ -172,25 +162,6 @@ describe('RecordValue', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should throw an error if attachment has incorrect storage location', function () {
|
|
||||||
const value = [
|
|
||||||
{
|
|
||||||
fileId: 1,
|
|
||||||
fileName: 'test',
|
|
||||||
notes: 'test',
|
|
||||||
storageLocation: 'Invalid',
|
|
||||||
},
|
|
||||||
];
|
|
||||||
|
|
||||||
expect(() =>
|
|
||||||
new RecordValue(
|
|
||||||
RecordValueType.AttachmentList,
|
|
||||||
2,
|
|
||||||
value
|
|
||||||
).asAttachmentArray()
|
|
||||||
).to.throw();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should throw an error if called on record value with incorrect type', function () {
|
it('should throw an error if called on record value with incorrect type', function () {
|
||||||
expect(() =>
|
expect(() =>
|
||||||
new RecordValue(RecordValueType.Integer, 2, []).asAttachmentArray()
|
new RecordValue(RecordValueType.Integer, 2, []).asAttachmentArray()
|
||||||
@@ -272,29 +243,31 @@ describe('RecordValue', function () {
|
|||||||
|
|
||||||
it('should return the value as an array of delegates for valid type', function () {
|
it('should return the value as an array of delegates for valid type', function () {
|
||||||
const value = [
|
const value = [
|
||||||
{
|
new Delegate(
|
||||||
delegateType: 'External',
|
DelegateType.External,
|
||||||
name: 'test',
|
'test',
|
||||||
emailAddress: 'test@test.com',
|
'test@test.com',
|
||||||
delegationDateTime: '2019-01-01T00:00:00.000Z',
|
new Date(),
|
||||||
delegationCompletedDateTime: '2019-01-01T00:00:00.000Z',
|
new Date()
|
||||||
},
|
),
|
||||||
{
|
new Delegate(
|
||||||
delegateType: 'External',
|
DelegateType.External,
|
||||||
name: null,
|
null,
|
||||||
emailAddress: 'test@test.com',
|
'test@test.com',
|
||||||
delegationDateTime: '2019-01-01T00:00:00.000Z',
|
new Date(),
|
||||||
delegationCompletedDateTime: null,
|
null
|
||||||
},
|
),
|
||||||
{
|
new Delegate(
|
||||||
delegateType: 'External',
|
DelegateType.External,
|
||||||
emailAddress: 'test@test.com',
|
'test',
|
||||||
delegationDateTime: '2019-01-01T00:00:00.000Z',
|
'test@test.com',
|
||||||
},
|
new Date(),
|
||||||
|
new Date()
|
||||||
|
),
|
||||||
];
|
];
|
||||||
|
|
||||||
const recordValue = new RecordValue(
|
const recordValue = new RecordValue(
|
||||||
RecordValueType.ScoringGroupList,
|
RecordValueType.DelegateList,
|
||||||
2,
|
2,
|
||||||
value
|
value
|
||||||
).asDelegateArray();
|
).asDelegateArray();
|
||||||
@@ -315,26 +288,6 @@ describe('RecordValue', function () {
|
|||||||
new RecordValue(RecordValueType.Integer, 2, []).asDelegateArray()
|
new RecordValue(RecordValueType.Integer, 2, []).asDelegateArray()
|
||||||
).to.throw();
|
).to.throw();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should throw an error if delegate has incorrect delegate type', function () {
|
|
||||||
const value = [
|
|
||||||
{
|
|
||||||
delegateType: 'Invalid',
|
|
||||||
name: 'test',
|
|
||||||
emailAddress: 'test@test.com',
|
|
||||||
delegationDateTime: '2019-01-01T00:00:00.000Z',
|
|
||||||
delegationCompletedDateTime: '2019-01-01T00:00:00.000Z',
|
|
||||||
},
|
|
||||||
];
|
|
||||||
|
|
||||||
expect(() =>
|
|
||||||
new RecordValue(
|
|
||||||
RecordValueType.ScoringGroupList,
|
|
||||||
2,
|
|
||||||
value
|
|
||||||
).asDelegateArray()
|
|
||||||
).to.throw();
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('asScoringGroupArray', function () {
|
describe('asScoringGroupArray', function () {
|
||||||
@@ -347,14 +300,7 @@ describe('RecordValue', function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should return the value as an array of scoring groups for valid type', function () {
|
it('should return the value as an array of scoring groups for valid type', function () {
|
||||||
const value = [
|
const value = [new ScoringGroup('1', 'test', 1, 1)];
|
||||||
{
|
|
||||||
listValueId: 'test',
|
|
||||||
name: 'test',
|
|
||||||
score: 1,
|
|
||||||
maximumScore: 1,
|
|
||||||
},
|
|
||||||
];
|
|
||||||
|
|
||||||
const recordValue = new RecordValue(
|
const recordValue = new RecordValue(
|
||||||
RecordValueType.ScoringGroupList,
|
RecordValueType.ScoringGroupList,
|
||||||
@@ -391,24 +337,21 @@ describe('RecordValue', function () {
|
|||||||
|
|
||||||
it('should return the value as a TimeSpanData for valid type', function () {
|
it('should return the value as a TimeSpanData for valid type', function () {
|
||||||
const cases = [
|
const cases = [
|
||||||
{
|
new TimeSpanData(
|
||||||
quantity: 1,
|
1,
|
||||||
increment: 'Days',
|
TimeSpanIncrement.Days,
|
||||||
recurrence: 'None',
|
TimeSpanRecurrenceType.None,
|
||||||
endAfterOccurrences: 1,
|
1,
|
||||||
endByDate: '2019-01-01T00:00:00.000Z',
|
new Date()
|
||||||
},
|
),
|
||||||
{
|
new TimeSpanData(1, TimeSpanIncrement.Days, null, null, null),
|
||||||
quantity: 1,
|
new TimeSpanData(
|
||||||
increment: 'Days',
|
1,
|
||||||
recurrence: null,
|
TimeSpanIncrement.Days,
|
||||||
endAfterOccurrences: null,
|
TimeSpanRecurrenceType.None,
|
||||||
endByDate: null,
|
1,
|
||||||
},
|
new Date()
|
||||||
{
|
),
|
||||||
quantity: 1,
|
|
||||||
increment: 'Days',
|
|
||||||
},
|
|
||||||
];
|
];
|
||||||
|
|
||||||
cases.forEach((value) => {
|
cases.forEach((value) => {
|
||||||
@@ -432,33 +375,5 @@ describe('RecordValue', function () {
|
|||||||
new RecordValue(RecordValueType.Integer, 2, []).asTimeSpanData()
|
new RecordValue(RecordValueType.Integer, 2, []).asTimeSpanData()
|
||||||
).to.throw();
|
).to.throw();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should throw an error if timespan has incorrect increment', function () {
|
|
||||||
const value = {
|
|
||||||
quantity: 1,
|
|
||||||
increment: 'Invalid',
|
|
||||||
recurrence: 'None',
|
|
||||||
endAfterOccurrences: 1,
|
|
||||||
endByDate: '2019-01-01T00:00:00.000Z',
|
|
||||||
};
|
|
||||||
|
|
||||||
expect(() =>
|
|
||||||
new RecordValue(RecordValueType.TimeSpan, 2, value).asTimeSpanData()
|
|
||||||
).to.throw();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should throw an error if timespan has incorrect recurrence', function () {
|
|
||||||
const value = {
|
|
||||||
quantity: 1,
|
|
||||||
increment: 'Days',
|
|
||||||
recurrence: 'Invalid',
|
|
||||||
endAfterOccurrences: 1,
|
|
||||||
endByDate: '2019-01-01T00:00:00.000Z',
|
|
||||||
};
|
|
||||||
|
|
||||||
expect(() =>
|
|
||||||
new RecordValue(RecordValueType.TimeSpan, 2, value).asTimeSpanData()
|
|
||||||
).to.throw();
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -0,0 +1,30 @@
|
|||||||
|
import { ScoringGroupListRecordValue } from '../src/models/ScoringGroupListRecordValue';
|
||||||
|
import { expect } from 'chai';
|
||||||
|
|
||||||
|
describe('ScoringGroupListRecordValue', function () {
|
||||||
|
it('should be defined', function () {
|
||||||
|
expect(ScoringGroupListRecordValue).to.not.be.undefined;
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should have a constructor', function () {
|
||||||
|
expect(ScoringGroupListRecordValue).to.have.property('constructor');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should hav a constructor that takes a fieldId and value', function () {
|
||||||
|
expect(ScoringGroupListRecordValue).to.have.lengthOf(2);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should have fieldId, value, and type properties', function () {
|
||||||
|
const scoringGroupListRecordValue = new ScoringGroupListRecordValue(1, []);
|
||||||
|
expect(scoringGroupListRecordValue).to.have.property('fieldId');
|
||||||
|
expect(scoringGroupListRecordValue).to.have.property('value');
|
||||||
|
expect(scoringGroupListRecordValue).to.have.property('type');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should have a constructor that sets its properties correctly', function () {
|
||||||
|
const scoringGroupListRecordValue = new ScoringGroupListRecordValue(1, []);
|
||||||
|
expect(scoringGroupListRecordValue.fieldId).to.equal(1);
|
||||||
|
expect(scoringGroupListRecordValue.value).to.deep.equal([]);
|
||||||
|
expect(scoringGroupListRecordValue.type).to.equal('ScoringGroupList');
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
import { StringListRecordValue } from '../src/models/StringListRecordValue';
|
||||||
|
import { expect } from 'chai';
|
||||||
|
|
||||||
|
describe('StringListRecordValue', function () {
|
||||||
|
it('should be defined', function () {
|
||||||
|
expect(StringListRecordValue).to.not.be.undefined;
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should have a constructor', function () {
|
||||||
|
expect(StringListRecordValue).to.have.property('constructor');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should hav a constructor that takes a fieldId and value', function () {
|
||||||
|
expect(StringListRecordValue).to.have.lengthOf(2);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should have fieldId, value, and type properties', function () {
|
||||||
|
const stringListRecordValue = new StringListRecordValue(1, []);
|
||||||
|
expect(stringListRecordValue).to.have.property('fieldId');
|
||||||
|
expect(stringListRecordValue).to.have.property('value');
|
||||||
|
expect(stringListRecordValue).to.have.property('type');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should have a constructor that sets its properties correctly', function () {
|
||||||
|
const stringListRecordValue = new StringListRecordValue(1, []);
|
||||||
|
expect(stringListRecordValue.fieldId).to.equal(1);
|
||||||
|
expect(stringListRecordValue.value).to.deep.equal([]);
|
||||||
|
expect(stringListRecordValue.type).to.equal('StringList');
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -0,0 +1,48 @@
|
|||||||
|
import { TimeSpanRecordValue } from '../src/models/TimeSpanRecordValue';
|
||||||
|
import { expect } from 'chai';
|
||||||
|
import { TimeSpanData } from '../src/models/TimeSpanData';
|
||||||
|
import { TimeSpanIncrement } from '../src/enums/TimeSpanIncrement';
|
||||||
|
import { TimeSpanRecurrenceType } from '../src/enums/TimeSpanRecurrenceType';
|
||||||
|
|
||||||
|
describe('TimeSpanRecordValue', function () {
|
||||||
|
it('should be defined', function () {
|
||||||
|
expect(TimeSpanRecordValue).to.not.be.undefined;
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should have a constructor', function () {
|
||||||
|
expect(TimeSpanRecordValue).to.have.property('constructor');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should hav a constructor that takes a fieldId and value', function () {
|
||||||
|
expect(TimeSpanRecordValue).to.have.lengthOf(2);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should have fieldId, value, and type properties', function () {
|
||||||
|
const timeSpanData = new TimeSpanData(
|
||||||
|
1,
|
||||||
|
TimeSpanIncrement.Days,
|
||||||
|
TimeSpanRecurrenceType.None,
|
||||||
|
null,
|
||||||
|
null
|
||||||
|
);
|
||||||
|
const timeSpanRecordValue = new TimeSpanRecordValue(1, timeSpanData);
|
||||||
|
expect(timeSpanRecordValue).to.have.property('fieldId');
|
||||||
|
expect(timeSpanRecordValue).to.have.property('value');
|
||||||
|
expect(timeSpanRecordValue).to.have.property('type');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should have a constructor that sets its properties correctly', function () {
|
||||||
|
const timeSpanData = new TimeSpanData(
|
||||||
|
1,
|
||||||
|
TimeSpanIncrement.Days,
|
||||||
|
TimeSpanRecurrenceType.None,
|
||||||
|
null,
|
||||||
|
null
|
||||||
|
);
|
||||||
|
const timeSpanRecordValue = new TimeSpanRecordValue(1, timeSpanData);
|
||||||
|
|
||||||
|
expect(timeSpanRecordValue.fieldId).to.equal(1);
|
||||||
|
expect(timeSpanRecordValue.value).to.deep.equal(timeSpanData);
|
||||||
|
expect(timeSpanRecordValue.type).to.equal('TimeSpan');
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -0,0 +1,416 @@
|
|||||||
|
/*
|
||||||
|
This file represents an exhaustive list of possible record value
|
||||||
|
objects that can be returned from the API. It is used in the
|
||||||
|
ApiResponse.spec.ts file to test the ApiResponse class when it returns
|
||||||
|
types involving records.
|
||||||
|
*/
|
||||||
|
export const testFieldData: object[] = [
|
||||||
|
{
|
||||||
|
type: 'StringList',
|
||||||
|
fieldId: 12891,
|
||||||
|
value: ['list_value_1', 'list_value_2'],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'Integer',
|
||||||
|
fieldId: 12144,
|
||||||
|
value: 1,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'Date',
|
||||||
|
fieldId: 12145,
|
||||||
|
value: '2023-01-17T05:52:07.251Z',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'Date',
|
||||||
|
fieldId: 12146,
|
||||||
|
value: '2023-02-10T01:19:46.63Z',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'String',
|
||||||
|
fieldId: 12152,
|
||||||
|
value: 'stevan.freeborn@onspring.com',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'Date',
|
||||||
|
fieldId: 12153,
|
||||||
|
value: '2023-01-17T05:53:12.104Z',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'Integer',
|
||||||
|
fieldId: 12160,
|
||||||
|
value: 69,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'String',
|
||||||
|
fieldId: 12165,
|
||||||
|
value: 'stevan.freeborn+delegate@onspring.com',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'String',
|
||||||
|
fieldId: 12166,
|
||||||
|
value: 'stevan_delegate',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'ScoringGroupList',
|
||||||
|
fieldId: 12167,
|
||||||
|
value: [
|
||||||
|
{
|
||||||
|
delegateType: 'External',
|
||||||
|
name: 'test_delegate',
|
||||||
|
emailAddress: 'test@test.com',
|
||||||
|
delegationType: 'AllPages',
|
||||||
|
pageIds: [],
|
||||||
|
answeredPageIds: [],
|
||||||
|
canReadOtherPages: false,
|
||||||
|
delegationDateTime: '2023-01-17T05:52:53.781Z',
|
||||||
|
delegationCompletedDateTime: '2023-01-17T05:53:12.617Z',
|
||||||
|
status: 'Pending',
|
||||||
|
isDeleted: false,
|
||||||
|
messagingDisplayText:
|
||||||
|
'Delegate Name: test_delegate -- Delegate Completed On: 1/17/2023 5:53 AM',
|
||||||
|
guid: '00000000-0000-0000-0000-000000000000',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
delegateType: 'External',
|
||||||
|
name: undefined,
|
||||||
|
emailAddress: 'test@test.com',
|
||||||
|
delegationType: 'AllPages',
|
||||||
|
pageIds: [],
|
||||||
|
answeredPageIds: [],
|
||||||
|
canReadOtherPages: false,
|
||||||
|
delegationDateTime: '2023-01-17T05:52:53.781Z',
|
||||||
|
delegationCompletedDateTime: undefined,
|
||||||
|
status: 'Pending',
|
||||||
|
isDeleted: false,
|
||||||
|
messagingDisplayText:
|
||||||
|
'Delegate Name: test_delegate -- Delegate Completed On: 1/17/2023 5:53 AM',
|
||||||
|
guid: '00000000-0000-0000-0000-000000000000',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
delegateType: 'External',
|
||||||
|
name: null,
|
||||||
|
emailAddress: 'test@test.com',
|
||||||
|
delegationType: 'AllPages',
|
||||||
|
pageIds: [],
|
||||||
|
answeredPageIds: [],
|
||||||
|
canReadOtherPages: false,
|
||||||
|
delegationDateTime: '2023-01-17T05:52:53.781Z',
|
||||||
|
delegationCompletedDateTime: null,
|
||||||
|
status: 'Pending',
|
||||||
|
isDeleted: false,
|
||||||
|
messagingDisplayText:
|
||||||
|
'Delegate Name: test_delegate -- Delegate Completed On: 1/17/2023 5:53 AM',
|
||||||
|
guid: '00000000-0000-0000-0000-000000000000',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'IntegerList',
|
||||||
|
fieldId: 12191,
|
||||||
|
value: [1],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'IntegerList',
|
||||||
|
fieldId: 12192,
|
||||||
|
value: [925],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'String',
|
||||||
|
fieldId: 12894,
|
||||||
|
value: 'test',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'Decimal',
|
||||||
|
fieldId: 12895,
|
||||||
|
value: 10,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'Guid',
|
||||||
|
fieldId: 12896,
|
||||||
|
value: '2b70ebb9-af45-4165-9a23-da44acce7bf7',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'Date',
|
||||||
|
fieldId: 12897,
|
||||||
|
value: '2023-02-10T07:19:46.629Z',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'Integer',
|
||||||
|
fieldId: 12144,
|
||||||
|
value: 2,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'Date',
|
||||||
|
fieldId: 12145,
|
||||||
|
value: '2023-01-24T04:03:06.13Z',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'Date',
|
||||||
|
fieldId: 12146,
|
||||||
|
value: '2023-02-10T04:06:29.985Z',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'Date',
|
||||||
|
fieldId: 12147,
|
||||||
|
value: '2023-02-10T04:06:29.985Z',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'Integer',
|
||||||
|
fieldId: 12148,
|
||||||
|
value: 2,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'Integer',
|
||||||
|
fieldId: 12149,
|
||||||
|
value: 2,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'Integer',
|
||||||
|
fieldId: 12150,
|
||||||
|
value: 2,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'String',
|
||||||
|
fieldId: 12151,
|
||||||
|
value: 'Stevan Freeborn',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'String',
|
||||||
|
fieldId: 12152,
|
||||||
|
value: 'stevan.freeborn@onspring.com',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'Date',
|
||||||
|
fieldId: 12153,
|
||||||
|
value: '2023-01-24T04:03:06.128Z',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'Decimal',
|
||||||
|
fieldId: 12155,
|
||||||
|
value: 6,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'Decimal',
|
||||||
|
fieldId: 12156,
|
||||||
|
value: 9,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'Decimal',
|
||||||
|
fieldId: 12157,
|
||||||
|
value: 66.66666666666667,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'Integer',
|
||||||
|
fieldId: 12160,
|
||||||
|
value: 73,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'ScoringGroupList',
|
||||||
|
fieldId: 12161,
|
||||||
|
value: [
|
||||||
|
{
|
||||||
|
listValueId: '0eac7224-f4bc-4121-8ca5-1fe75f5cd576',
|
||||||
|
name: 'group_one',
|
||||||
|
score: 2,
|
||||||
|
maximumScore: 3,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
listValueId: '743ddd0d-702d-414d-87d4-0aa4fe0c265e',
|
||||||
|
name: 'group_two',
|
||||||
|
score: 2,
|
||||||
|
maximumScore: 4,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
listValueId: '4ff35205-bfe8-4639-8574-d0458fa7f85e',
|
||||||
|
name: 'group_three',
|
||||||
|
score: 2,
|
||||||
|
maximumScore: 2,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'Decimal',
|
||||||
|
fieldId: 12162,
|
||||||
|
value: 9,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'Decimal',
|
||||||
|
fieldId: 12163,
|
||||||
|
value: 66.66666666666667,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'ScoringGroupList',
|
||||||
|
fieldId: 12164,
|
||||||
|
value: [
|
||||||
|
{
|
||||||
|
listValueId: '0eac7224-f4bc-4121-8ca5-1fe75f5cd576',
|
||||||
|
name: 'group_one',
|
||||||
|
score: 2,
|
||||||
|
maximumScore: 3,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
listValueId: '743ddd0d-702d-414d-87d4-0aa4fe0c265e',
|
||||||
|
name: 'group_two',
|
||||||
|
score: 2,
|
||||||
|
maximumScore: 4,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
listValueId: '4ff35205-bfe8-4639-8574-d0458fa7f85e',
|
||||||
|
name: 'group_three',
|
||||||
|
score: 2,
|
||||||
|
maximumScore: 2,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'String',
|
||||||
|
fieldId: 12165,
|
||||||
|
value: 'stevan.freeborn@onspring.com',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'String',
|
||||||
|
fieldId: 12166,
|
||||||
|
value: 'Stevan Freeborn',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'IntegerList',
|
||||||
|
fieldId: 12191,
|
||||||
|
value: [2, 3, 4, 5, 6, 7],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'IntegerList',
|
||||||
|
fieldId: 12192,
|
||||||
|
value: [925],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'String',
|
||||||
|
fieldId: 12263,
|
||||||
|
value: '2',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'Date',
|
||||||
|
fieldId: 12884,
|
||||||
|
value: '2023-02-09T06:00:00Z',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'Guid',
|
||||||
|
fieldId: 12885,
|
||||||
|
value: 'e75b49cf-adb7-4b8e-a7e5-93ebf1948dba',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'Decimal',
|
||||||
|
fieldId: 12886,
|
||||||
|
value: 100,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'String',
|
||||||
|
fieldId: 12887,
|
||||||
|
value: 'this is a test',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'AttachmentList',
|
||||||
|
fieldId: 12888,
|
||||||
|
value: [
|
||||||
|
{
|
||||||
|
fileId: 1348,
|
||||||
|
fileName: 'onspring-api-playground.py',
|
||||||
|
notes: '',
|
||||||
|
storageLocation: 'Internal',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
fileId: 1349,
|
||||||
|
fileName: 'core_isolation_warning.png',
|
||||||
|
notes: '',
|
||||||
|
storageLocation: 'Internal',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
fileId: 1349,
|
||||||
|
fileName: 'core_isolation_warning.png',
|
||||||
|
notes: null,
|
||||||
|
storageLocation: 'Internal',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
fileId: 1349,
|
||||||
|
fileName: 'core_isolation_warning.png',
|
||||||
|
notes: undefined,
|
||||||
|
storageLocation: 'Internal',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'FileList',
|
||||||
|
fieldId: 12889,
|
||||||
|
value: [1350, 1351],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'Integer',
|
||||||
|
fieldId: 12890,
|
||||||
|
value: 2,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'GuidList',
|
||||||
|
fieldId: 12891,
|
||||||
|
value: [
|
||||||
|
'd7471a5f-6718-4368-8734-3e3e712bacd9',
|
||||||
|
'3b3de61f-fa44-4e51-b70d-35992c2a1a6e',
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'IntegerList',
|
||||||
|
fieldId: 12892,
|
||||||
|
value: [4, 5],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'TimeSpan',
|
||||||
|
fieldId: 12893,
|
||||||
|
value: {
|
||||||
|
quantity: 10,
|
||||||
|
increment: 'Days',
|
||||||
|
recurrence: 'EndByDate',
|
||||||
|
endAfterOccurrences: 10,
|
||||||
|
endByDate: '2023-02-16T06:00:00Z',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'TimeSpan',
|
||||||
|
fieldId: 12893,
|
||||||
|
value: {
|
||||||
|
quantity: 10,
|
||||||
|
increment: 'Days',
|
||||||
|
recurrence: null,
|
||||||
|
endAfterOccurrences: null,
|
||||||
|
endByDate: null,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'TimeSpan',
|
||||||
|
fieldId: 12893,
|
||||||
|
value: {
|
||||||
|
quantity: 10,
|
||||||
|
increment: 'Days',
|
||||||
|
recurrence: undefined,
|
||||||
|
endAfterOccurrences: undefined,
|
||||||
|
endByDate: undefined,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'String',
|
||||||
|
fieldId: 12894,
|
||||||
|
value: 'test',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'Decimal',
|
||||||
|
fieldId: 12895,
|
||||||
|
value: 10,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'Guid',
|
||||||
|
fieldId: 12896,
|
||||||
|
value: '2b70ebb9-af45-4165-9a23-da44acce7bf7',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'Date',
|
||||||
|
fieldId: 12897,
|
||||||
|
value: '2023-02-10T07:19:47.002Z',
|
||||||
|
},
|
||||||
|
];
|
||||||
Reference in New Issue
Block a user