Skip to content

Commit 257a264

Browse files
committed
feat: uppercase method name when returning from the url_builder
1 parent a67d16c commit 257a264

File tree

4 files changed

+47
-36
lines changed

4 files changed

+47
-36
lines changed

src/router/signed_url_builder.ts

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,9 @@ export function createSignedUrlBuilder<Routes extends LookupList>(
5757
}
5858

5959
signedRoute.get = function routeGet(...[identifier, params, options]) {
60-
const url = createSignedUrlForRoute(identifier, params, options, 'GET')
61-
const method = 'get'
60+
const method = 'GET'
61+
const url = createSignedUrlForRoute(identifier, params, options, method)
62+
6263
return {
6364
url,
6465
method,
@@ -73,8 +74,9 @@ export function createSignedUrlBuilder<Routes extends LookupList>(
7374
}
7475

7576
signedRoute.post = function routePost(...[identifier, params, options]) {
76-
const url = createSignedUrlForRoute(identifier, params, options, 'POST')
77-
const method = 'post'
77+
const method = 'POST'
78+
const url = createSignedUrlForRoute(identifier, params, options, method)
79+
7880
return {
7981
url,
8082
method,
@@ -89,8 +91,9 @@ export function createSignedUrlBuilder<Routes extends LookupList>(
8991
}
9092

9193
signedRoute.put = function routePut(...[identifier, params, options]) {
92-
const url = createSignedUrlForRoute(identifier, params, options, 'PUT')
93-
const method = 'put'
94+
const method = 'PUT'
95+
const url = createSignedUrlForRoute(identifier, params, options, method)
96+
9497
return {
9598
url,
9699
method,
@@ -105,8 +108,9 @@ export function createSignedUrlBuilder<Routes extends LookupList>(
105108
}
106109

107110
signedRoute.patch = function routePatch(...[identifier, params, options]) {
108-
const url = createSignedUrlForRoute(identifier, params, options, 'PATCH')
109-
const method = 'patch'
111+
const method = 'PATCH'
112+
const url = createSignedUrlForRoute(identifier, params, options, method)
113+
110114
return {
111115
url,
112116
method,
@@ -121,8 +125,9 @@ export function createSignedUrlBuilder<Routes extends LookupList>(
121125
}
122126

123127
signedRoute.delete = function routeDelete(...[identifier, params, options]) {
124-
const url = createSignedUrlForRoute(identifier, params, options, 'DELETE')
125-
const method = 'delete'
128+
const method = 'DELETE'
129+
const url = createSignedUrlForRoute(identifier, params, options, method)
130+
126131
return {
127132
url,
128133
method,
@@ -138,6 +143,7 @@ export function createSignedUrlBuilder<Routes extends LookupList>(
138143

139144
signedRoute.method = function routeGet(method, ...[identifier, params, options]) {
140145
const url = createSignedUrlForRoute(identifier, params, options, method)
146+
141147
return {
142148
url,
143149
method,

src/router/url_builder.ts

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,9 @@ export function createUrlBuilder<Routes extends LookupList>(
5454
}
5555

5656
urlFor.get = function urlForMethodGet(...[identifier, params, options]) {
57-
const url = createUrlForRoute(identifier, params, options, 'GET')
58-
const method = 'get'
57+
const method = 'GET'
58+
const url = createUrlForRoute(identifier, params, options, method)
59+
5960
return {
6061
url,
6162
method,
@@ -70,8 +71,9 @@ export function createUrlBuilder<Routes extends LookupList>(
7071
}
7172

7273
urlFor.post = function urlForMethodPost(...[identifier, params, options]) {
73-
const url = createUrlForRoute(identifier, params, options, 'POST')
74-
const method = 'post'
74+
const method = 'POST'
75+
const url = createUrlForRoute(identifier, params, options, method)
76+
7577
return {
7678
url,
7779
method,
@@ -86,8 +88,9 @@ export function createUrlBuilder<Routes extends LookupList>(
8688
}
8789

8890
urlFor.put = function urlForMethodPut(...[identifier, params, options]) {
89-
const url = createUrlForRoute(identifier, params, options, 'PUT')
90-
const method = 'put'
91+
const method = 'PUT'
92+
const url = createUrlForRoute(identifier, params, options, method)
93+
9194
return {
9295
url,
9396
method,
@@ -102,8 +105,9 @@ export function createUrlBuilder<Routes extends LookupList>(
102105
}
103106

104107
urlFor.patch = function urlForMethodPatch(...[identifier, params, options]) {
105-
const url = createUrlForRoute(identifier, params, options, 'PATCH')
106-
const method = 'patch'
108+
const method = 'PATCH'
109+
const url = createUrlForRoute(identifier, params, options, method)
110+
107111
return {
108112
url,
109113
method,
@@ -118,8 +122,9 @@ export function createUrlBuilder<Routes extends LookupList>(
118122
}
119123

120124
urlFor.delete = function urlForMethodDelete(...[identifier, params, options]) {
121-
const url = createUrlForRoute(identifier, params, options, 'DELETE')
122-
const method = 'delete'
125+
const method = 'DELETE'
126+
const url = createUrlForRoute(identifier, params, options, method)
127+
123128
return {
124129
url,
125130
method,

src/types/url_builder.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ export type UrlFor<Routes extends LookupList, Options extends any = URLOptions>
124124
Routes['GET'][RouteIdentifier],
125125
Options
126126
>
127-
): { method: 'get'; url: string; form: { action: string; method: 'get' } }
127+
): { method: 'GET'; url: string; form: { action: string; method: 'GET' } }
128128

129129
/**
130130
* Make URL for a POST route. An error will be raised if the route doesn't
@@ -141,7 +141,7 @@ export type UrlFor<Routes extends LookupList, Options extends any = URLOptions>
141141
Routes['POST'][RouteIdentifier],
142142
Options
143143
>
144-
): { method: 'post'; url: string; form: { action: string; method: 'post' } }
144+
): { method: 'POST'; url: string; form: { action: string; method: 'POST' } }
145145

146146
/**
147147
* Make URL for a PUT route. An error will be raised if the route doesn't
@@ -158,7 +158,7 @@ export type UrlFor<Routes extends LookupList, Options extends any = URLOptions>
158158
Routes['PUT'][RouteIdentifier],
159159
Options
160160
>
161-
): { method: 'put'; url: string; form: { action: string; method: 'put' } }
161+
): { method: 'PUT'; url: string; form: { action: string; method: 'PUT' } }
162162

163163
/**
164164
* Make URL for a PATCH route. An error will be raised if the route doesn't
@@ -175,7 +175,7 @@ export type UrlFor<Routes extends LookupList, Options extends any = URLOptions>
175175
Routes['PATCH'][RouteIdentifier],
176176
Options
177177
>
178-
): { method: 'patch'; url: string; form: { action: string; method: 'patch' } }
178+
): { method: 'PATCH'; url: string; form: { action: string; method: 'PATCH' } }
179179

180180
/**
181181
* Make URL for a DELETE route. An error will be raised if the route doesn't
@@ -192,7 +192,7 @@ export type UrlFor<Routes extends LookupList, Options extends any = URLOptions>
192192
Routes['DELETE'][RouteIdentifier],
193193
Options
194194
>
195-
): { method: 'delete'; url: string; form: { action: string; method: 'delete' } }
195+
): { method: 'DELETE'; url: string; form: { action: string; method: 'DELETE' } }
196196

197197
/**
198198
* Make URL for a custom route method. An error will be raised if the route doesn't

tests/router/url_builder.spec.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ test.group('URLBuilder', () => {
3939
assert.equal(urlFor('users.show', ['1']), '/users/1')
4040
})
4141

42-
test('create url for a specific methods', ({ assert }) => {
42+
test('create url for specific methods', ({ assert }) => {
4343
const router = new RouterFactory().create()
4444

4545
const { urlFor } = new URLBuilderFactory<{
@@ -87,49 +87,49 @@ test.group('URLBuilder', () => {
8787
router.route('/users/:id', ['GET', 'PUT', 'PATCH', 'DELETE'], () => {}).as('users.show')
8888
router.commit()
8989

90-
assert.containSubset(urlFor.get('users.show', { id: '1' }), { method: 'get', url: '/users/1' })
90+
assert.containSubset(urlFor.get('users.show', { id: '1' }), { method: 'GET', url: '/users/1' })
9191
assert.deepEqual(urlFor.get('users.show', { id: '1' }).form, {
92-
method: 'get',
92+
method: 'GET',
9393
action: '/users/1',
9494
})
9595
assert.equal(`${urlFor.get('users.show', { id: '1' })}`, '/users/1')
9696

9797
assert.containSubset(urlFor.post('users.index'), {
98-
method: 'post',
98+
method: 'POST',
9999
url: '/users',
100100
})
101101
assert.deepEqual(urlFor.post('users.index').form, {
102-
method: 'post',
102+
method: 'POST',
103103
action: '/users',
104104
})
105105
assert.equal(`${urlFor.post('users.index')}`, '/users')
106106

107107
assert.containSubset(urlFor.put('users.show', { id: '1' }), {
108-
method: 'put',
108+
method: 'PUT',
109109
url: '/users/1',
110110
})
111111
assert.deepEqual(urlFor.put('users.show', { id: '1' }).form, {
112-
method: 'put',
112+
method: 'PUT',
113113
action: '/users/1',
114114
})
115115
assert.equal(`${urlFor.put('users.show', { id: '1' })}`, '/users/1')
116116

117117
assert.containSubset(urlFor.patch('users.show', { id: '1' }), {
118-
method: 'patch',
118+
method: 'PATCH',
119119
url: '/users/1',
120120
})
121121
assert.deepEqual(urlFor.patch('users.show', { id: '1' }).form, {
122-
method: 'patch',
122+
method: 'PATCH',
123123
action: '/users/1',
124124
})
125125
assert.equal(`${urlFor.patch('users.show', { id: '1' })}`, '/users/1')
126126

127127
assert.containSubset(urlFor.delete('users.show', { id: '1' }), {
128-
method: 'delete',
128+
method: 'DELETE',
129129
url: '/users/1',
130130
})
131131
assert.deepEqual(urlFor.delete('users.show', { id: '1' }).form, {
132-
method: 'delete',
132+
method: 'DELETE',
133133
action: '/users/1',
134134
})
135135
assert.equal(`${urlFor.delete('users.show', { id: '1' })}`, '/users/1')

0 commit comments

Comments
 (0)