@compassdigital/sdk.typescript 3.0.0-beta.10 → 3.0.0-beta.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/order.ts CHANGED
@@ -376,12 +376,12 @@ export interface GetOrderCustomerOrdersBrandRequest extends GetOrderCustomerOrde
376
376
 
377
377
  // GET /order/location/brand/{id} - Get all orders for a location Brand
378
378
 
379
- export interface GetOrderBrandOrdersPath {
379
+ export interface GetOrderLocationBrandPath {
380
380
  // The location brand ID
381
381
  id: string;
382
382
  }
383
383
 
384
- export interface GetOrderBrandOrdersQuery {
384
+ export interface GetOrderLocationBrandQuery {
385
385
  // Filter orders by their pickup date. Only return orders that have a date greater than or equal to the date in milliseconds.
386
386
  pickup_start?: number;
387
387
  // Filter orders by their pickup date. Only return orders that have a date less than or equal to the date in milliseconds.
@@ -398,11 +398,11 @@ export interface GetOrderBrandOrdersQuery {
398
398
  limit?: number;
399
399
  }
400
400
 
401
- export type GetOrderBrandOrdersResponse = Orders;
401
+ export type GetOrderLocationBrandResponse = Orders;
402
402
 
403
- export interface GetOrderBrandOrdersRequest
404
- extends GetOrderBrandOrdersQuery,
405
- GetOrderBrandOrdersPath {}
403
+ export interface GetOrderLocationBrandRequest
404
+ extends GetOrderLocationBrandQuery,
405
+ GetOrderLocationBrandPath {}
406
406
 
407
407
  // GET /order/location/{id} - Get all orders for a location
408
408
 
package/template.ejs CHANGED
@@ -1,5 +1,5 @@
1
1
 
2
- import { BaseServiceClient, RequestOptions } from "./base";
2
+ import { BaseServiceClient, RequestOptions, ResponsePromise } from "./base";
3
3
  export * from "./base";
4
4
 
5
5
  export class ServiceClient extends BaseServiceClient {
@@ -14,7 +14,7 @@ export class ServiceClient extends BaseServiceClient {
14
14
  * @param <%- param.name %><%- param.description ? " - " + param.description : "" %>
15
15
  <% } -%>
16
16
  */
17
- <%- name %>(<% for (let i = 0; i < params.length; i++) { %><%- i > 0 ? ", " : "" %><%- params[i].name %><%= params[i].required ? "" : "?" %>: <%- params[i].type %><% } %>): Promise<<%= response %>> {
17
+ <%- name %>(<% for (let i = 0; i < params.length; i++) { %><%- i > 0 ? ", " : "" %><%- params[i].name %><%= params[i].required ? "" : "?" %>: <%- params[i].type %><% } %>): ResponsePromise<<%= response %>> {
18
18
  return this.request(<% for (let i = 0; i < args.length; i++) { %><%- i > 0 ? ", " : "" %><%- args[i] %><% } %>);
19
19
  }
20
20
  <% } %>
@@ -79,7 +79,7 @@ describe("ServiceClient", () => {
79
79
  intercept: async (req) => {
80
80
  attempts++;
81
81
  return { ok: false, status: 500, body: "something went wrong"};
82
- }
82
+ },
83
83
  });
84
84
  try {
85
85
  const task = await api.get_task("", { retry: 5 });
@@ -103,7 +103,7 @@ describe("ServiceClient", () => {
103
103
  return { ok: false, status: 501, body: "" };
104
104
  }
105
105
  });
106
- const task = await ServiceError.ignore([501], api.get_task(""));
106
+ const task = await api.get_task("").ignore(501);
107
107
  expect(task).toBeNull();
108
108
  });
109
109
 
@@ -113,7 +113,7 @@ describe("ServiceClient", () => {
113
113
  return { ok: false, status: 500, body: JSON.stringify({ code: 500.4, message: "uh oh" }) };
114
114
  }
115
115
  });
116
- const task = await ServiceError.ignore([500.4], api.get_task(""));
116
+ const task = await api.get_task("").ignore(500.4);
117
117
  expect(task).toBeNull();
118
118
  });
119
119
 
@@ -131,5 +131,27 @@ describe("ServiceClient", () => {
131
131
  expect(ServiceError.code(err)).toBe(500.4);
132
132
  }
133
133
  });
134
+
135
+ test("either should be true with 200 response", async () => {
136
+ const api = new ServiceClient({
137
+ intercept: async (req) => {
138
+ return { ok: true, status: 200, body: "{}" };
139
+ }
140
+ });
141
+ const res = await api.get_task("{}").combine();
142
+ expect(res.ok).toBe(true);
143
+ expect(res.body).toBeTruthy();
144
+ });
145
+
146
+ test("either should be false with non-200 response", async () => {
147
+ const api = new ServiceClient({
148
+ intercept: async (req) => {
149
+ return { ok: false, status: 400, body: "{}" };
150
+ }
151
+ });
152
+ const res = await api.get_task("{}").combine();
153
+ expect(res.ok).toBe(false);
154
+ expect(res.err).toBeInstanceOf(ServiceError);
155
+ });
134
156
  });
135
157
  });
@@ -0,0 +1,22 @@
1
+
2
+ import { OperationObject, OperationParams, Schema } from "@icholy/openapi-ts";
3
+ import { CodeGenerator } from "../gen";
4
+
5
+ describe("CodeGenerator", () => {
6
+ describe("inferName", () => {
7
+ const gen = new CodeGenerator();
8
+ test("/order/location/brand/{id}", () => {
9
+ const op: OperationObject = {
10
+ operationId: "get_brand_orders",
11
+ }
12
+ const name = gen.inferName({
13
+ method: "get",
14
+ params: new OperationParams(op),
15
+ path: "/order/location/brand/{id}",
16
+ obj: op,
17
+ }, { name: "order", swagger: "" });
18
+ expect(name.pascal).toBe("GetOrderLocationBrand");
19
+ expect(name.snake).toBe("get_order_location_brand");
20
+ });
21
+ });
22
+ });