|
| 1 | +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. |
| 2 | + |
| 3 | +import Runloop from '@runloop/api-client'; |
| 4 | +import { Response } from 'node-fetch'; |
| 5 | + |
| 6 | +const client = new Runloop({ |
| 7 | + bearerToken: 'My Bearer Token', |
| 8 | + baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010', |
| 9 | +}); |
| 10 | + |
| 11 | +describe('resource axons', () => { |
| 12 | + test('create', async () => { |
| 13 | + const responsePromise = client.axons.create(); |
| 14 | + const rawResponse = await responsePromise.asResponse(); |
| 15 | + expect(rawResponse).toBeInstanceOf(Response); |
| 16 | + const response = await responsePromise; |
| 17 | + expect(response).not.toBeInstanceOf(Response); |
| 18 | + const dataAndResponse = await responsePromise.withResponse(); |
| 19 | + expect(dataAndResponse.data).toBe(response); |
| 20 | + expect(dataAndResponse.response).toBe(rawResponse); |
| 21 | + }); |
| 22 | + |
| 23 | + test('create: request options and params are passed correctly', async () => { |
| 24 | + // ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error |
| 25 | + await expect(client.axons.create({}, { path: '/_stainless_unknown_path' })).rejects.toThrow( |
| 26 | + Runloop.NotFoundError, |
| 27 | + ); |
| 28 | + }); |
| 29 | + |
| 30 | + test('retrieve', async () => { |
| 31 | + const responsePromise = client.axons.retrieve('id'); |
| 32 | + const rawResponse = await responsePromise.asResponse(); |
| 33 | + expect(rawResponse).toBeInstanceOf(Response); |
| 34 | + const response = await responsePromise; |
| 35 | + expect(response).not.toBeInstanceOf(Response); |
| 36 | + const dataAndResponse = await responsePromise.withResponse(); |
| 37 | + expect(dataAndResponse.data).toBe(response); |
| 38 | + expect(dataAndResponse.response).toBe(rawResponse); |
| 39 | + }); |
| 40 | + |
| 41 | + test('retrieve: request options instead of params are passed correctly', async () => { |
| 42 | + // ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error |
| 43 | + await expect(client.axons.retrieve('id', { path: '/_stainless_unknown_path' })).rejects.toThrow( |
| 44 | + Runloop.NotFoundError, |
| 45 | + ); |
| 46 | + }); |
| 47 | + |
| 48 | + test('list', async () => { |
| 49 | + const responsePromise = client.axons.list(); |
| 50 | + const rawResponse = await responsePromise.asResponse(); |
| 51 | + expect(rawResponse).toBeInstanceOf(Response); |
| 52 | + const response = await responsePromise; |
| 53 | + expect(response).not.toBeInstanceOf(Response); |
| 54 | + const dataAndResponse = await responsePromise.withResponse(); |
| 55 | + expect(dataAndResponse.data).toBe(response); |
| 56 | + expect(dataAndResponse.response).toBe(rawResponse); |
| 57 | + }); |
| 58 | + |
| 59 | + test('list: request options instead of params are passed correctly', async () => { |
| 60 | + // ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error |
| 61 | + await expect(client.axons.list({ path: '/_stainless_unknown_path' })).rejects.toThrow( |
| 62 | + Runloop.NotFoundError, |
| 63 | + ); |
| 64 | + }); |
| 65 | + |
| 66 | + test('publish: only required params', async () => { |
| 67 | + const responsePromise = client.axons.publish('id', { |
| 68 | + event_type: 'event_type', |
| 69 | + origin: 'EXTERNAL_EVENT', |
| 70 | + payload: 'payload', |
| 71 | + source: 'source', |
| 72 | + }); |
| 73 | + const rawResponse = await responsePromise.asResponse(); |
| 74 | + expect(rawResponse).toBeInstanceOf(Response); |
| 75 | + const response = await responsePromise; |
| 76 | + expect(response).not.toBeInstanceOf(Response); |
| 77 | + const dataAndResponse = await responsePromise.withResponse(); |
| 78 | + expect(dataAndResponse.data).toBe(response); |
| 79 | + expect(dataAndResponse.response).toBe(rawResponse); |
| 80 | + }); |
| 81 | + |
| 82 | + test('publish: required and optional params', async () => { |
| 83 | + const response = await client.axons.publish('id', { |
| 84 | + event_type: 'event_type', |
| 85 | + origin: 'EXTERNAL_EVENT', |
| 86 | + payload: 'payload', |
| 87 | + source: 'source', |
| 88 | + }); |
| 89 | + }); |
| 90 | + |
| 91 | + test('subscribeSse', async () => { |
| 92 | + const responsePromise = client.axons.subscribeSse('id'); |
| 93 | + const rawResponse = await responsePromise.asResponse(); |
| 94 | + expect(rawResponse).toBeInstanceOf(Response); |
| 95 | + const response = await responsePromise; |
| 96 | + expect(response).not.toBeInstanceOf(Response); |
| 97 | + const dataAndResponse = await responsePromise.withResponse(); |
| 98 | + expect(dataAndResponse.data).toBe(response); |
| 99 | + expect(dataAndResponse.response).toBe(rawResponse); |
| 100 | + }); |
| 101 | +}); |
0 commit comments