test: add tests for routes

This commit is contained in:
Jovan Krunić
2020-09-28 11:12:56 +02:00
committed by Rainer Killinger
parent 751693bebc
commit d3955b3cdd
22 changed files with 1315 additions and 455 deletions

View File

@@ -13,33 +13,15 @@
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
// the list provides option to easily implement "isHttpMethod" guard
const httpVerbs = ['get', 'post', 'put', 'delete', 'patch', 'options',
'head', 'checkout', 'copy', 'lock', 'merge', 'mkactivity', 'mkcol',
'move', 'm-search', 'notify', 'purge', 'report', 'search', 'subscribe',
'trace', 'unlock','unsubscribe'] as const;
/**
* Strings that can be used as HTTP verbs (e.g. in requests)
* Strings that can be used as HTTP verbs (e.g. in requests): 'get' | 'post' | 'put' | 'delete' etc.
*/
export type HTTPVerb = 'all' |
'get' |
'post' |
'put' |
'delete' |
'patch' |
'options' |
'head' |
'checkout' |
'copy' |
'lock' |
'merge' |
'mkactivity' |
'mkcol' |
'move' |
'm-search' |
'notify' |
'purge' |
'report' |
'search' |
'subscribe' |
'trace' |
'unlock' |
'unsubscribe';
export type HTTPVerb = typeof httpVerbs[number];
/**
* Provides information if a text (representing a method) is an HTTP verb
@@ -47,5 +29,5 @@ export type HTTPVerb = 'all' |
* @param method A text (representing a method) to check
*/
export function isHttpMethod(method: string): method is HTTPVerb {
return ['get', 'post', 'put'].indexOf(method) > -1;
return (httpVerbs as unknown as string[]).indexOf(method) > -1;
}