feat: continuing to work on implementing records methods

This commit is contained in:
StevanFreeborn
2023-02-10 00:49:50 -06:00
parent fde8b50717
commit 6ba77ce1d4
14 changed files with 494 additions and 105 deletions
+4
View File
@@ -0,0 +1,4 @@
export enum DelegateType {
External = 'External',
Internal = 'Internal',
}
+30
View File
@@ -16,6 +16,7 @@ import { GetPagedReportsResponse } from './GetPagedReportsResponse';
import { ListField } from './ListField';
import { ListItemResponse } from './ListItemResponse';
import { ListValue } from './ListValue';
import { Record } from './Record';
import { ReferenceField } from './ReferenceField';
import { Report } from './Report';
import { ReportData } from './ReportData';
@@ -308,6 +309,10 @@ export class ApiResponse<T> {
);
}
/**
* @method asReportDataType - Converts the ApiResponse to an ApiResponse<ReportData>.
* @returns {ApiResponse<ReportData>} - An ApiResponse<ReportData>.
*/
asReportDataType(): ApiResponse<ReportData> {
const apiResponse = this as ApiResponse<any>;
@@ -324,15 +329,40 @@ export class ApiResponse<T> {
);
}
/**
* @method asRecordType - Converts the ApiResponse to an ApiResponse<Record>.
* @returns {ApiResponse<Record>} - An ApiResponse<Record>.
*/
public asRecordType(): ApiResponse<Record> {
const apiResponse = this as ApiResponse<any>;
const record = new Record(
apiResponse.data.appId,
apiResponse.data.recordId,
apiResponse.data.fieldData
);
return new ApiResponse<Record>(
apiResponse.statusCode,
apiResponse.message,
record
);
}
/**
* @method asFileCollectionType - Converts the field item to the appropriate field object based upon the field item's type.
* @param {any} fieldItem - The field item to convert.
* @returns {Field} - The converted field object.
* @throws {Error} - If the field item's type is unknown.
*/
private static getFieldByType(fieldItem: any): Field {
const type = FieldType[fieldItem.type];
const status = FieldStatus[fieldItem.status];
if (type === undefined) {
throw new Error(`Unknown field type: ${fieldItem.type as string}`);
}
switch (type) {
case FieldType.Reference: {
const multiplicity = Multiplicity[fieldItem.multiplicity];
+35 -7
View File
@@ -1,14 +1,42 @@
export class Attachment {
public fileId: number;
public fileName: string;
public notes: string;
public storageLocation: string;
import { type FileStorageSite } from '../enums/FileStorageSite';
/**
* @class Attachment - Represents an attachment.
*/
export class Attachment {
/**
* @property {number} fileId - The id of the file.
*/
public fileId: number;
/**
* @property {string} fileName - The name of the file.
*/
public fileName: string;
/**
* @property {string | null} notes - The notes associated with the file.
*/
public notes: string | null;
/**
* @property {FileStorageSite} storageLocation - The storage location of the file.
*/
public storageLocation: FileStorageSite;
/**
* @constructor - Creates a new instance of Attachment.
* @param {number} fileId - The id of the file.
* @param {string} fileName - The name of the file.
* @param {string | null} notes - The notes associated with the file.
* @param {FileStorageSite} storageLocation - The storage location of the file.
* @returns {Attachment} - A new instance of Attachment.
*/
constructor(
fileId: number,
fileName: string,
notes: string,
storageLocation: string
notes: string | null,
storageLocation: FileStorageSite
) {
this.fileId = fileId;
this.fileName = fileName;
+54
View File
@@ -0,0 +1,54 @@
import { type DelegateType } from '../enums/DelegateType';
/**
* @class Delegate - Represents a delegate.
*/
export class Delegate {
/**
* @property {DelegateType} delegateType - The type of delegate.
*/
public delegateType: DelegateType;
/**
* @property {string | null} name - The name of the delegate.
*/
public name: string | null;
/**
* @property {string} emailAddress - The email address of the delegate.
*/
public emailAddress: string;
/**
* @property {Date} delegationDateTime - The date and time the delegate was assigned.
*/
public delegationDateTime: Date;
/**
* @property {Date | null} delegationCompletedDateTime - The date and time the delegate completed the survey.
*/
public delegationCompletedDateTime: Date | null;
/**
* @constructor - Creates a new instance of Delegate.
* @param {DelegateType} delegateType - The type of delegate.
* @param {string | null} name - The name of the delegate.
* @param {string} emailAddress - The email address of the delegate.
* @param {Date} delegationDateTime - The date and time the delegate was assigned.
* @param {Date | null} delegationCompletedDateTime - The date and time the delegate completed the survey.
* @returns {Delegate} - A new instance of Delegate.
*/
constructor(
delegateType: DelegateType,
name: string | null,
emailAddress: string,
delegationDateTime: Date,
delegationCompletedDateTime: Date | null
) {
this.delegateType = delegateType;
this.name = name;
this.emailAddress = emailAddress;
this.delegationDateTime = delegationDateTime;
this.delegationCompletedDateTime = delegationCompletedDateTime;
}
}
+8 -27
View File
@@ -1,7 +1,3 @@
import { type DataFormat } from '../enums/DataFormat';
import { type ReportDataType } from '../enums/ReportDataType';
import { type PagingRequest } from './PagingRequest';
/**
* @class EndpointFactory - A factory class for creating endpoints.
*/
@@ -16,11 +12,10 @@ export class EndpointFactory {
/**
* @method getAppsEndpoint - Gets the apps endpoint.
* @param {PagingRequest} pagingRequest - Pagination information to use as query params in the endpoint string.
* @returns {string} - The apps endpoint.
*/
public static getAppsEndpoint(pagingRequest: PagingRequest): string {
return `/Apps?pageSize=${pagingRequest.pageSize}&pageNumber=${pagingRequest.pageNumber}`;
public static getAppsEndpoint(): string {
return `/Apps`;
}
/**
@@ -60,14 +55,10 @@ export class EndpointFactory {
/**
* @method getFieldsByAppIdEndpoint - Gets the fields by app id endpoint.
* @param {number} id - The id of the app.
* @param {PagingRequest} pagingRequest - Pagination information to use as query params in the endpoint string.
* @returns {string} - The fields by app id endpoint.
*/
public static getFieldsByAppIdEndpoint(
id: number,
pagingRequest: PagingRequest
): string {
return `/Fields/appId/${id}?pageSize=${pagingRequest.pageSize}&pageNumber=${pagingRequest.pageNumber}`;
public static getFieldsByAppIdEndpoint(id: number): string {
return `/Fields/appId/${id}`;
}
/**
@@ -212,28 +203,18 @@ export class EndpointFactory {
/**
* @method getReportByIdEndpoint - Gets the get report by id endpoint.
* @param {number} reportId - The id of the report.
* @param {DataFormat} apiDataFormat - The data format that will be used to make the request.
* @param {ReportDataType} reportDataType - The report data type that will be used to make the request.
* @returns {string} - The get report by id endpoint.
*/
public static getReportByIdEndpoint(
reportId: number,
apiDataFormat: DataFormat,
reportDataType: ReportDataType
): string {
return `/Reports/id/${reportId}?apiDataFormat=${apiDataFormat}&dataType=${reportDataType}`;
public static getReportByIdEndpoint(reportId: number): string {
return `/Reports/id/${reportId}`;
}
/**
* @method getReportsByAppIdEndpoint - Gets the get reports by app id endpoint.
* @param {number} appId - The id of the app.
* @param {PagingRequest} pagingRequest - The paging information that will be used to make the request.
* @returns {string} - The get reports by app id endpoint.
*/
public static getReportsByAppIdEndpoint(
appId: number,
pagingRequest: PagingRequest
): string {
return `/Reports/appId/${appId}?pageSize=${pagingRequest.pageSize}&pageNumber=${pagingRequest.pageNumber}`;
public static getReportsByAppIdEndpoint(appId: number): string {
return `/Reports/appId/${appId}`;
}
}
+3
View File
@@ -1,6 +1,9 @@
import { type Field } from './Field';
import { PagedResponse } from './PagedResponse';
/**
* @class GetPagedFieldsResponse - A response containing a paged collection of fields.
*/
export class GetPagedFieldsResponse extends PagedResponse<Field> {
/**
* @constructor - Creates a new instance of the GetPagedAppsResponse class.
+26
View File
@@ -0,0 +1,26 @@
import { type Record } from './Record';
import { PagedResponse } from './PagedResponse';
/**
* @class GetPagedRecordsResponse - A response containing a paged collection of records.
*/
export class GetPagedRecordsResponse extends PagedResponse<Record> {
/**
* @constructor - Creates a new instance of the GetPagedRecordsResponse class.
* @param {Record[]} items - The items in the collection.
* @param {number} pageNumber - The page number of the response.
* @param {number} pageSize - The page size of the response.
* @param {number} totalPages - The total number of pages in the response.
* @param {number} totalRecords - The total number of records in the response.
* @returns {GetPagedRecordsResponse} - A new instance of the GetPagedRecordsResponse class.
*/
constructor(
items: Record[],
pageNumber: number,
pageSize: number,
totalPages: number,
totalRecords: number
) {
super(items, pageNumber, pageSize, totalPages, totalRecords);
}
}
+46
View File
@@ -0,0 +1,46 @@
import { type DataFormat } from '../enums/DataFormat';
/**
* @class GetRecordRequest - A request to get a record.
*/
export class GetRecordRequest {
/**
* @property {number} appId - The id of the app that the record belongs to.
*/
public appId: number;
/**
* @property {number} recordId - The id of the record.
*/
public recordId: number;
/**
* @property {number[]} fieldIds - The ids of the fields to include in the response.
*/
public fieldIds: number[];
/**
* @property {DataFormat} dataFormat - The format of the data in the response.
*/
public dataFormat: DataFormat;
/**
* @constructor - Creates a new instance of GetRecordRequest.
* @param {number} appId - The id of the app that the record belongs to.
* @param {number} recordId - The id of the record.
* @param {number[]} fieldIds - The ids of the fields to include in the response.
* @param {DataFormat} dataFormat - The format of the data in the response.
* @returns {GetRecordRequest} - A new instance of GetRecordRequest.
*/
constructor(
appId: number,
recordId: number,
fieldIds: number[],
dataFormat: DataFormat
) {
this.appId = appId;
this.recordId = recordId;
this.fieldIds = fieldIds;
this.dataFormat = dataFormat;
}
}
+38 -20
View File
@@ -20,6 +20,8 @@ import { type ListItemResponse } from './ListItemResponse';
import { type ListItemRequest } from './ListItemRequest';
import { type GetPagedReportsResponse } from './GetPagedReportsResponse';
import { type ReportData } from './ReportData';
import { type Record } from './Record';
import { type GetRecordRequest } from './GetRecordRequest';
/**
* @class OnspringClient - A client that can communicate with the Onspring API.
@@ -75,9 +77,9 @@ export class OnspringClient {
public async getApps(
pagingRequest: PagingRequest = new PagingRequest(1, 50)
): Promise<ApiResponse<GetPagedAppsResponse>> {
const endpoint = EndpointFactory.getAppsEndpoint(pagingRequest);
const apiResponse = await this.get<any>(endpoint);
const endpoint = EndpointFactory.getAppsEndpoint();
const params = { ...pagingRequest };
const apiResponse = await this.get<any>(endpoint, { params });
if (apiResponse.isSuccessful === false) {
return apiResponse;
@@ -167,11 +169,9 @@ export class OnspringClient {
appId: number,
pagingRequest: PagingRequest = new PagingRequest(1, 50)
): Promise<ApiResponse<GetPagedFieldsResponse>> {
const endpoint = EndpointFactory.getFieldsByAppIdEndpoint(
appId,
pagingRequest
);
const apiResponse = await this.get<any>(endpoint);
const endpoint = EndpointFactory.getFieldsByAppIdEndpoint(appId);
const params = { ...pagingRequest };
const apiResponse = await this.get<any>(endpoint, { params });
if (apiResponse.isSuccessful === false) {
return apiResponse;
@@ -310,6 +310,20 @@ export class OnspringClient {
return apiResponse;
}
public async getRecordById(
request: GetRecordRequest
): Promise<ApiResponse<Record>> {
const { appId, recordId, ...params } = request;
const endpoint = EndpointFactory.getRecordByIdEndpoint(appId, recordId);
const apiResponse = await this.get<any>(endpoint, { params });
if (apiResponse.isSuccessful === false) {
return apiResponse;
}
return apiResponse.asRecordType();
}
/**
* @method getReportsByAppId - Gets a paged list of reports by the app id.
* @param {number} appId - The id of the app to get the reports for.
@@ -320,12 +334,9 @@ export class OnspringClient {
appId: number,
pagingRequest: PagingRequest = new PagingRequest(1, 50)
): Promise<ApiResponse<GetPagedReportsResponse>> {
const endpoint = EndpointFactory.getReportsByAppIdEndpoint(
appId,
pagingRequest
);
const apiResponse = await this.get<any>(endpoint);
const endpoint = EndpointFactory.getReportsByAppIdEndpoint(appId);
const params = { ...pagingRequest };
const apiResponse = await this.get<any>(endpoint, { params });
if (apiResponse.isSuccessful === false) {
return apiResponse;
@@ -334,18 +345,25 @@ export class OnspringClient {
return apiResponse.asGetPagedReportsResponseType();
}
/**
* @method getReportById - Gets a report by its id.
* @param {number} reportId - The id of the report to get.
* @param {DataFormat} apiDataFormat - The data format that the report data will be returned in.
* @param {ReportDataType} dataType - The type of data that will be returned.
* @returns {Promise<ApiResponse<ReportData>>} - A promise that resolves to an ApiResponse of type ReportData.
*/
public async getReportById(
reportId: number,
apiDataFormat: DataFormat = DataFormat.Raw,
reportDataType: ReportDataType = ReportDataType.ReportData
dataType: ReportDataType = ReportDataType.ReportData
): Promise<ApiResponse<ReportData>> {
const endpoint = EndpointFactory.getReportByIdEndpoint(
reportId,
const endpoint = EndpointFactory.getReportByIdEndpoint(reportId);
const params = {
apiDataFormat,
reportDataType
);
dataType,
};
const apiResponse = await this.get<any>(endpoint);
const apiResponse = await this.get<any>(endpoint, { params });
if (apiResponse.isSuccessful === false) {
return apiResponse;
+4 -8
View File
@@ -15,22 +15,18 @@ export class Record {
public recordId: number;
/**
* @property {Array<RecordValue<any>>} fieldData - The data for the fields in the record.
* @property {RecordValue[]} fieldData - The data for the fields in the record.
*/
public fieldData: Array<RecordValue<any>>;
public fieldData: RecordValue[];
/**
* @constructor - Creates a new instance of Record.
* @param {number} appId - The id of the app that the record belongs to.
* @param {number} recordId - The id of the record.
* @param {Array<RecordValue<any>>} fieldData - The data for the fields in the record.
* @param {RecordValue[]} fieldData - The data for the fields in the record.
* @returns {Record} - A new instance of Record.
*/
constructor(
appId: number,
recordId: number,
fieldData: Array<RecordValue<any>>
) {
constructor(appId: number, recordId: number, fieldData: RecordValue[]) {
this.appId = appId;
this.recordId = recordId;
this.fieldData = fieldData;
+226 -6
View File
@@ -1,9 +1,17 @@
import { type RecordValueType } from '../enums/RecordValueType';
import { DelegateType } from '../enums/DelegateType';
import { FileStorageSite } from '../enums/FileStorageSite';
import { RecordValueType } from '../enums/RecordValueType';
import { TimeSpanIncrement } from '../enums/TimeSpanIncrement';
import { TimeSpanRecurrenceType } from '../enums/TimeSpanRecurrenceType';
import { Attachment } from './Attachment';
import { Delegate } from './Delegate';
import { ScoringGroup } from './ScoringGroup';
import { TimeSpanData } from './TimeSpanData';
/**
* @class RecordValue - A value for a field in a record.
*/
export class RecordValue<T> {
export class RecordValue {
/**
* @property {RecordValueType} type - The type of the record value.
*/
@@ -15,20 +23,232 @@ export class RecordValue<T> {
public fieldId: number;
/**
* @property {T} value - The value of the field.
* @property {any} value - The value of the field.
*/
public value: T;
public value: any;
/**
* @constructor - Creates a new instance of RecordValue.
* @param {RecordValueType} type - The type of the record value.
* @param {number} fieldId - The id of the field.
* @param {T} value - The value of the field.
* @param {any} value - The value of the field.
* @returns {RecordValue} - A new instance of RecordValue.
*/
constructor(type: RecordValueType, fieldId: number, value: T) {
constructor(type: RecordValueType, fieldId: number, value: any) {
this.type = type;
this.fieldId = fieldId;
this.value = value;
}
/**
* @method asString - Gets the value as a string.
* @returns {string} - The value as a string.
* @throws {Error} - If the value is not a string.
*/
public asString(): string {
this.validateType([RecordValueType.String, RecordValueType.Guid]);
return this.value;
}
/**
* @method asNumber - Gets the value as a number.
* @returns {number} - The value as a number.
* @throws {Error} - If the value is not a number.
*/
public asNumber(): number {
this.validateType([RecordValueType.Integer, RecordValueType.Decimal]);
return this.value;
}
/**
* @method asDate - Gets the value as a date.
* @returns {Date} - The value as a date.
* @throws {Error} - If the value is not a date.
*/
public asDate(): Date {
this.validateType([RecordValueType.Date]);
return new Date(this.value);
}
/**
* @method asAttachmentArray - Gets the value as an array of attachments.
* @returns {Attachment[]} - The value as an array of attachments.
* @throws {Error} - If the value is not an array of attachments.
* @throws {Error} - If the storage location is not a valid FileStorageSite.
*/
public asAttachmentArray(): Attachment[] {
this.validateType([RecordValueType.AttachmentList]);
const storageLocation = FileStorageSite[this.value.storageLocation];
if (storageLocation === undefined) {
throw new Error(
`${
this.value.storageLocation as string
} is not a valid FileStorageSite.`
);
}
return this.value.map((attachment: any) => {
const hasNotes =
attachment.notes !== null && attachment.notes !== undefined;
const notes = hasNotes ? attachment.notes : null;
return new Attachment(
attachment.fileId,
attachment.fileName,
notes,
storageLocation
);
});
}
/**
* @method asNumberArray - Gets the value as an array of numbers.
* @returns {number[]} - The value as an array of numbers.
* @throws {Error} - If the value is not an array of numbers.
*/
public asNumberArray(): number[] {
this.validateType([RecordValueType.FileList, RecordValueType.IntegerList]);
return this.value;
}
/**
* @method asStringArray - Gets the value as an array of strings.
* @returns {string[]} - The value as an array of strings.
* @throws {Error} - If the value is not an array of strings.
*/
public asStringArray(): string[] {
this.validateType([RecordValueType.StringList, RecordValueType.GuidList]);
return this.value;
}
/**
* @method asDelegateArray - Gets 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 a delegate type is not valid.
*/
public asDelegateArray(): Delegate[] {
this.validateType([RecordValueType.ScoringGroupList]);
return this.value.map((delegate: any) => {
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
);
});
}
/**
* @method asScoringGroupArray - Gets the value as an array of scoring groups.
* @returns {ScoringGroup[]} - The value as an array of scoring groups.
* @throws {Error} - If the value is not an array of scoring groups.
*/
public asScoringGroupArray(): ScoringGroup[] {
this.validateType([RecordValueType.ScoringGroupList]);
return this.value.map(
(scoringGroup: any) =>
new ScoringGroup(
scoringGroup.listValueId,
scoringGroup.name,
scoringGroup.score,
scoringGroup.maximunScore
)
);
}
/**
* @method asTimeSpanData - Gets 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 increment is not valid.
* @throws {Error} - If the recurrence is not valid.
*/
public asTimeSpanData(): TimeSpanData {
this.validateType([RecordValueType.TimeSpan]);
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
);
}
/**
* @method validateType - Validates the type of the field value.
* @param {RecordValueType[]} expectedTypes - The expected types.
* @throws {Error} - If the type is not valid.
*/
private validateType(expectedTypes: RecordValueType[]): void {
if (expectedTypes.includes(this.type) === false) {
throw new Error(
`Unable to get value for field value. Field value type must be of the following types: ${expectedTypes.join(
', '
)}. Actual type: ${this.type}`
);
}
}
}
+9 -9
View File
@@ -15,30 +15,30 @@ export class TimeSpanData {
/**
* @property {TimeSpanRecurrence} recurrence - The recurrence of the time span.
*/
public recurrence: TimeSpanRecurrenceType;
public recurrence: TimeSpanRecurrenceType | null;
/**
* @property {number} endAfterOccurrences - The number of occurrences of the time span.
*/
public endAfterOccurrences: number;
public endAfterOccurrences: number | null;
public endByDate: Date;
public endByDate: Date | null;
/**
* @constructor - Creates a new instance of TimeSpanData.
* @param {number} quantity - The quantity of the time span.
* @param {TimeSpanIncrement} increment - The increment of the time span.
* @param {TimeSpanRecurrenceType} recurrence - The recurrence of the time span.
* @param {number} endAfterOccurrences - The number of occurrences of the time span.
* @param {Date} endByDate - The end date of the time span.
* @param {TimeSpanRecurrenceType | null} recurrence - The recurrence of the time span.
* @param {number | null} endAfterOccurrences - The number of occurrences of the time span.
* @param {Date | null} endByDate - The end date of the time span.
* @returns {TimeSpanData} - A new instance of TimeSpanData.
*/
constructor(
quantity: number,
increment: TimeSpanIncrement,
recurrence: TimeSpanRecurrenceType,
endAfterOccurrences: number,
endByDate: Date
recurrence: TimeSpanRecurrenceType | null,
endAfterOccurrences: number | null,
endByDate: Date | null
) {
this.quantity = quantity;
this.increment = increment;
+8 -25
View File
@@ -1,8 +1,5 @@
import { EndpointFactory } from '../src/models/EndpointFactory';
import { expect } from 'chai';
import { PagingRequest } from '../src/models/PagingRequest';
import { DataFormat } from '../src/enums/DataFormat';
import { ReportDataType } from '../src/enums/ReportDataType';
describe('EndpointFactory', function () {
describe('getPingEndpoint', function () {
@@ -14,10 +11,8 @@ describe('EndpointFactory', function () {
describe('getAppsEndpoint', function () {
it('should return the correct apps endpoint with paging params based on paging request parameter passed', function () {
const result = EndpointFactory.getAppsEndpoint(
new PagingRequest(2, 1000)
);
expect(result).to.equal('/Apps?pageSize=1000&pageNumber=2');
const result = EndpointFactory.getAppsEndpoint();
expect(result).to.equal('/Apps');
});
});
@@ -51,11 +46,8 @@ describe('EndpointFactory', function () {
describe('getFieldsByAppIdEndpoint', function () {
it('should return the correct fields by app id endpoint', function () {
const result = EndpointFactory.getFieldsByAppIdEndpoint(
1,
new PagingRequest(2, 1000)
);
expect(result).to.equal('/Fields/appId/1?pageSize=1000&pageNumber=2');
const result = EndpointFactory.getFieldsByAppIdEndpoint(1);
expect(result).to.equal('/Fields/appId/1');
});
});
@@ -157,24 +149,15 @@ describe('EndpointFactory', function () {
describe('getReportByIdEndpoint', function () {
it('should return the correct report by id endpoint', function () {
const result = EndpointFactory.getReportByIdEndpoint(
1,
DataFormat.Raw,
ReportDataType.ReportData
);
expect(result).to.equal(
'/Reports/id/1?apiDataFormat=Raw&dataType=ReportData'
);
const result = EndpointFactory.getReportByIdEndpoint(1);
expect(result).to.equal('/Reports/id/1');
});
});
describe('getReportsByAppIdEndpoint', function () {
it('should return the correct reports by app id endpoint', function () {
const result = EndpointFactory.getReportsByAppIdEndpoint(
1,
new PagingRequest(2, 1000)
);
expect(result).to.equal('/Reports/appId/1?pageSize=1000&pageNumber=2');
const result = EndpointFactory.getReportsByAppIdEndpoint(1);
expect(result).to.equal('/Reports/appId/1');
});
});
});
+3 -3
View File
@@ -5,7 +5,6 @@ import axios, {
type InternalAxiosRequestConfig,
} from 'axios';
import { expect } from 'chai';
import * as sinon from 'sinon';
import { GetPagedAppsResponse } from '../src/models/GetPagedAppsResponse';
import { App } from '../src/models/App';
import { CollectionResponse } from '../src/models/CollectionResponse';
@@ -18,13 +17,14 @@ import { Readable } from 'stream';
import { CreatedWithIdResponse } from '../src/models/CreatedWithIdResponse';
import { FileInfo } from '../src/models/FileInfo';
import { File } from '../src/models/File';
import fs from 'fs';
import path from 'path';
import { ListItemRequest } from '../src/models/ListItemRequest';
import { ListItemResponse } from '../src/models/ListItemResponse';
import { Report } from '../src/models/Report';
import { GetPagedReportsResponse } from '../src/models/GetPagedReportsResponse';
import { ReportData } from '../src/models/ReportData';
import fs from 'fs';
import path from 'path';
import * as sinon from 'sinon';
describe('OnspringClient', function () {
const baseUrl = 'https://api.onspring.dev';