fix: begin writing Lists integration tests. fix: list item response model's id value should be of type string so modified the created with id response model that it extends so that the id property is generically typed and type can be passed in.

This commit is contained in:
Stevan Freeborn
2023-02-17 14:27:33 -06:00
parent 369540d3c8
commit bc8b9a4977
10 changed files with 148 additions and 32 deletions
+7 -5
View File
@@ -219,17 +219,19 @@ export class ApiResponse<T> {
}
/**
* @method asCreatedWithIdResponseType - Converts the ApiResponse to an ApiResponse<CreatedWithIdResponse>.
* @returns {ApiResponse<CreatedWithIdResponse>} - An ApiResponse<CreatedWithIdResponse>.
* @method asCreatedWithIdResponseType - Converts the ApiResponse to an ApiResponse<CreatedWithIdResponse<T>>.
* @returns {ApiResponse<CreatedWithIdResponse<T>>} - An ApiResponse<CreatedWithIdResponse<T>>.
*/
public asCreatedWithIdResponseType(): ApiResponse<CreatedWithIdResponse> {
public asCreatedWithIdResponseType<T>(): ApiResponse<
CreatedWithIdResponse<T>
> {
const apiResponse = this as ApiResponse<any>;
const createdWithIdResponse = new CreatedWithIdResponse(
const createdWithIdResponse = new CreatedWithIdResponse<T>(
apiResponse.data.id
);
return new ApiResponse<CreatedWithIdResponse>(
return new ApiResponse<CreatedWithIdResponse<T>>(
apiResponse.statusCode,
apiResponse.message,
createdWithIdResponse
+5 -5
View File
@@ -1,15 +1,15 @@
export class CreatedWithIdResponse {
export class CreatedWithIdResponse<T> {
/**
* @property {number} id - The id of the created object.
* @property {T} id - The id of the created object.
*/
public id: number;
public id: T;
/**
* @constructor - Creates a new instance of the CreatedWithIdResponse class.
* @param id - The id of the created object.
* @returns {CreatedWithIdResponse} - A new instance of the CreatedWithIdResponse class.
* @returns {CreatedWithIdResponse<T>} - A new instance of the CreatedWithIdResponse class.
*/
constructor(id: number) {
constructor(id: T) {
this.id = id;
}
}
+12 -12
View File
@@ -8,9 +8,9 @@ export class ListItemRequest {
public listId: number;
/**
* @property {string} id - The id for the list item.
* @property {string | null} id - The id for the list item.
*/
public id: string;
public id: string | null;
/**
* @property {string} name - The name of the list item.
@@ -18,30 +18,30 @@ export class ListItemRequest {
public name: string;
/**
* @property {number} numericValue - The numeric value of the list item.
* @property {number | null} numericValue - The numeric value of the list item.
*/
public numericValue: number;
public numericValue: number | null;
/**
* @property {string} color - The color of the list item.
* @property {string | null} color - The color of the list item.
*/
public color: string;
public color: string | null;
/**
* @constructor - Creates a new instance of the ListItemRequest class.
* @param {number} listId - The id for the list that the item belongs to.
* @param {string} id - The id for the list item.
* @param {string | null} id - The id for the list item.
* @param {string} name - The name of the list item.
* @param {number} numericValue - The numeric value of the list item.
* @param {string} color - The color of the list item.
* @param {number | null} numericValue - The numeric value of the list item.
* @param {string | null} color - The color of the list item.
* @returns {ListItemRequest} - A new instance of the ListItemRequest class.
*/
constructor(
listId: number,
id: string,
id: string | null,
name: string,
numericValue: number,
color: string
numericValue: number | null,
color: string | null
) {
this.listId = listId;
this.id = id;
+3 -4
View File
@@ -1,15 +1,14 @@
import { CreatedWithIdResponse } from './CreatedWithIdResponse';
/**
* @class ListItemResponse - Represents a respons when a list item is created or updated.
*/
export class ListItemResponse extends CreatedWithIdResponse {
export class ListItemResponse extends CreatedWithIdResponse<string> {
/**
* @constructor - Creates a new instance of ListItemResponse.
* @param {number} id - The id of the list item.
* @param {string} id - The id of the list item.
* @returns {ListItemResponse} - A new instance of ListItemResponse.
*/
constructor(id: number) {
constructor(id: string) {
super(id);
}
}
+3 -3
View File
@@ -264,11 +264,11 @@ export class OnspringClient {
/**
* @method saveFile - Saves a file to a record in Onspring.
* @param {SaveFileRequest} request - The request that will be used to save the file.
* @returns {Promise<ApiResponse<CreatedWithIdResponse>>} - A promise that resolves to an ApiResponse of type CreatedWithIdResponse.
* @returns {Promise<ApiResponse<CreatedWithIdResponse<number>>>} - A promise that resolves to an ApiResponse of type CreatedWithIdResponse.
*/
public async saveFile(
request: SaveFileRequest
): Promise<ApiResponse<CreatedWithIdResponse>> {
): Promise<ApiResponse<CreatedWithIdResponse<number>>> {
const endpoint = EndpointFactory.getSaveFileEndpoint();
const formData = request.asFormData();
const apiResponse = await this.post<any>(endpoint, formData, {
@@ -279,7 +279,7 @@ export class OnspringClient {
return apiResponse;
}
return apiResponse.asCreatedWithIdResponseType();
return apiResponse.asCreatedWithIdResponseType<number>();
}
public async deleteFileById(
+1 -1
View File
@@ -1,6 +1,6 @@
import { CreatedWithIdResponse } from './CreatedWithIdResponse';
export class SaveRecordResponse extends CreatedWithIdResponse {
export class SaveRecordResponse extends CreatedWithIdResponse<number> {
public warnings: string[];
constructor(id: number, warnings: string[] = []) {