Skip to content

Commit 03486f1

Browse files
committedJan 26, 2022
docs(api-calls): updated to uppercase method names
Updated all method argument to `call` to uppercase for consistency
1 parent 5fdcf8a commit 03486f1

File tree

3 files changed

+25
-25
lines changed

3 files changed

+25
-25
lines changed
 

‎docs/calliope/api-calls.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ import User from '@Models/User';
9898

9999
const user = new User();
100100

101-
await user.call('get', { query: 'value' }); // GET your-api.com/users?query=value
101+
await user.call('GET', { query: 'value' }); // GET your-api.com/users?query=value
102102
```
103103

104104
### Endpoint manipulation

‎src/Calliope/Concerns/CallsApi.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ export default class CallsApi extends BuildsQuery {
177177
public async get<T extends Model = this>(
178178
queryParameters?: QueryParams & Record<string, unknown>
179179
): Promise<ModelCollection<T> | T> {
180-
return this.call('get', queryParameters)
180+
return this.call('GET', queryParameters)
181181
.then(responseData => this.newInstanceFromResponseData<T>(this.getDataFromResponse(responseData)));
182182
}
183183

@@ -204,7 +204,7 @@ export default class CallsApi extends BuildsQuery {
204204
*/
205205
// @ts-expect-error - despite TS2526, it still infers correctly
206206
public async post<T extends Model = this>(data: Attributes | FormData): Promise<T> {
207-
return this.call('post', data)
207+
return this.call('POST', data)
208208
.then(responseData => this.getResponseModel<T>(this.getDataFromResponse(responseData)));
209209
}
210210

@@ -217,7 +217,7 @@ export default class CallsApi extends BuildsQuery {
217217
*/
218218
// @ts-expect-error - despite TS2526, it still infers correctly
219219
public async put<T extends Model = this>(data: Attributes | FormData): Promise<T> {
220-
return this.call('put', data)
220+
return this.call('PUT', data)
221221
.then(responseData => this.getResponseModel<T>(this.getDataFromResponse(responseData)));
222222
}
223223

@@ -230,7 +230,7 @@ export default class CallsApi extends BuildsQuery {
230230
*/
231231
// @ts-expect-error - despite TS2526, it still infers correctly
232232
public async patch<T extends Model = this>(data: Attributes | FormData): Promise<T> {
233-
return this.call('patch', data)
233+
return this.call('PATCH', data)
234234
.then(responseData => this.getResponseModel<T>(this.getDataFromResponse(responseData)));
235235
}
236236

@@ -244,7 +244,7 @@ export default class CallsApi extends BuildsQuery {
244244
*/
245245
// @ts-expect-error - despite TS2526, it still infers correctly
246246
public async delete<T extends Model = this>(data?: Attributes | FormData): Promise<T> {
247-
return this.call('delete', data)
247+
return this.call('DELETE', data)
248248
.then(responseData => this.getResponseModel<T>(this.getDataFromResponse(responseData)));
249249
}
250250

‎tests/Calliope/Concerns/CallsApi.test.ts

+19-19
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,15 @@ describe('CallsApi', () => {
3232
describe('.serverAttributeCasing', () => {
3333
it('should cast the outgoing attributes to the set serverAttributeCasing', async () => {
3434
fetchMock.mockResponseOnce(async () => Promise.resolve(buildResponse(User.factory().raw())));
35-
await caller.call('post', { someValue: 1 });
35+
await caller.call('POST', { someValue: 1 });
3636

3737
// eslint-disable-next-line @typescript-eslint/naming-convention
3838
expect(getLastRequest()?.body).toStrictEqual({ some_value: 1 });
3939
});
4040

4141
it('should recursively cast the keys to any depth', async () => {
4242
fetchMock.mockResponseOnce(async () => Promise.resolve(buildResponse(User.factory().raw())));
43-
await caller.call('post', {
43+
await caller.call('POST', {
4444
someValue: {
4545
anotherValue: 1
4646
}
@@ -61,7 +61,7 @@ describe('CallsApi', () => {
6161

6262
const user = new UserWithSnakeCase;
6363

64-
await user.call('post', {
64+
await user.call('POST', {
6565
// eslint-disable-next-line @typescript-eslint/naming-convention
6666
some_value: {
6767
// eslint-disable-next-line @typescript-eslint/naming-convention
@@ -77,7 +77,7 @@ describe('CallsApi', () => {
7777
formData.append('my_field', 'value');
7878
fetchMock.mockResponseOnce(async () => Promise.resolve(buildResponse(User.factory().raw())));
7979

80-
await caller.call('post', formData);
80+
await caller.call('POST', formData);
8181

8282
expect((getLastRequest()?.body as FormData).has('my_field')).toBe(true);
8383
expect((getLastRequest()?.body as FormData).has('myField')).toBe(false);
@@ -99,7 +99,7 @@ describe('CallsApi', () => {
9999
caller.setEndpoint('');
100100

101101
// awkward syntax comes from https://github.com/facebook/jest/issues/1700
102-
await expect(caller.call('get')).rejects.toStrictEqual(
102+
await expect(caller.call('GET')).rejects.toStrictEqual(
103103
new LogicException(
104104
'Endpoint is not defined when calling \'get\' method on \'' + caller.constructor.name + '\'.'
105105
)
@@ -109,18 +109,18 @@ describe('CallsApi', () => {
109109
it('should get the endpoint from the model as expected', async () => {
110110
const baseEndpoint = config.get('baseEndPoint');
111111
fetchMock.mockResponse(async () => Promise.resolve(buildResponse()));
112-
await caller.call('get');
112+
await caller.call('GET');
113113
// it adds the '/' between the baseEndPoint and the endpoint
114114
expect(getLastRequest()?.url).toBe(finish(baseEndpoint!, '/') + caller.getEndpoint());
115115

116116
config.unset('baseEndPoint');
117-
await caller.call('get');
117+
await caller.call('GET');
118118
// if no baseEndPoint is set, we have no leading '/'
119119
expect(getLastRequest()?.url).toBe(caller.getEndpoint());
120120

121121
config.set('baseEndPoint', baseEndpoint);
122122
caller.getEndpoint = () => 'https://test-domain.com/users';
123-
await caller.call('get');
123+
await caller.call('GET');
124124
// it just appends the value regardless of if it's a valid url
125125
expect(getLastRequest()?.url).toBe(finish(baseEndpoint!, '/') + caller.getEndpoint());
126126

@@ -129,7 +129,7 @@ describe('CallsApi', () => {
129129

130130
it('should return a promise with the response', async () => {
131131
fetchMock.mockResponseOnce(async () => Promise.resolve(buildResponse(User.factory().raw())));
132-
const responseData = await caller.call('get');
132+
const responseData = await caller.call('GET');
133133

134134
expect(responseData).toStrictEqual(User.factory().raw());
135135
});
@@ -147,7 +147,7 @@ describe('CallsApi', () => {
147147
config.set('api', api);
148148

149149
fetchMock.mockResponseOnce(async () => Promise.resolve(buildResponse()));
150-
await caller.call('get');
150+
await caller.call('GET');
151151
expect(getLastRequest()?.headers.has('custom')).toBe(true);
152152
expect(getLastRequest()?.headers.get('custom')).toBe('header');
153153
});
@@ -163,7 +163,7 @@ describe('CallsApi', () => {
163163
config.set('apiResponseHandler', apiResponseHandler);
164164

165165
fetchMock.mockResponseOnce(async () => Promise.resolve(buildResponse()));
166-
await caller.call('get');
166+
await caller.call('GET');
167167
expect(mockFn).toHaveBeenCalled();
168168
});
169169

@@ -172,8 +172,8 @@ describe('CallsApi', () => {
172172
async () => Promise.resolve(buildResponse((User.factory().create() as User).getRawOriginal()))
173173
);
174174

175-
const promise1 = caller.call('get');
176-
const promise2 = caller.call('get');
175+
const promise1 = caller.call('GET');
176+
const promise2 = caller.call('GET');
177177

178178
// @ts-expect-error
179179
expect(caller.requestCount).toBe(2);
@@ -189,7 +189,7 @@ describe('CallsApi', () => {
189189
async () => Promise.resolve(buildResponse((User.factory().create() as User).getRawOriginal()))
190190
);
191191

192-
const promise = caller.call('get');
192+
const promise = caller.call('GET');
193193

194194
expect(caller.loading).toBe(true);
195195

@@ -200,7 +200,7 @@ describe('CallsApi', () => {
200200

201201
it('should send all the given data', async () => {
202202
fetchMock.mockResponseOnce(async () => Promise.resolve(buildResponse(User.factory().raw())));
203-
await caller.call('post', {
203+
await caller.call('POST', {
204204
falsyKey1: null,
205205
falsyKey2: undefined,
206206
falsyKey3: false,
@@ -220,7 +220,7 @@ describe('CallsApi', () => {
220220
it('should not parse the response body if data wrapped', async () => {
221221
const data = User.factory().raw();
222222
fetchMock.mockResponseOnce(async () => Promise.resolve(buildResponse({ data })));
223-
const parsedResponse = await caller.call('get');
223+
const parsedResponse = await caller.call('GET');
224224

225225
expect(parsedResponse).toStrictEqual({ data });
226226
});
@@ -247,7 +247,7 @@ describe('CallsApi', () => {
247247

248248
it('should return undefined if the response from the handler is undefined', async () => {
249249
fetchMock.mockResponseOnce(async () => Promise.resolve(buildResponse(undefined, { status: 100 })));
250-
await expect(caller.call('get')).resolves.toBeUndefined();
250+
await expect(caller.call('GET')).resolves.toBeUndefined();
251251
});
252252

253253
describe('requestMiddleware', () => {
@@ -313,7 +313,7 @@ describe('CallsApi', () => {
313313

314314
fetchMock.mockResponseOnce(async () => Promise.resolve(buildResponse(User.factory().raw())));
315315
await caller.call(
316-
'post',
316+
'POST',
317317
{ key: 'value' },
318318
{ header: 'value' }
319319
);
@@ -332,7 +332,7 @@ describe('CallsApi', () => {
332332

333333
fetchMock.mockResponseOnce(async () => Promise.resolve(buildResponse(User.factory().raw())));
334334
await caller.call(
335-
'get',
335+
'GET',
336336
{ key: 'value' },
337337
{ header: 'value' }
338338
);

0 commit comments

Comments
 (0)