From eecff514c29c45400a022a811d494bf1959f8656 Mon Sep 17 00:00:00 2001 From: Johann150 Date: Sun, 7 May 2023 23:33:21 +0200 Subject: [PATCH] tests: use bearer authentication --- packages/backend/test/utils.ts | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/packages/backend/test/utils.ts b/packages/backend/test/utils.ts index a366547e6..59a62452c 100644 --- a/packages/backend/test/utils.ts +++ b/packages/backend/test/utils.ts @@ -31,16 +31,15 @@ export const async = (fn: Function) => (done: Function) => { export const api = async (endpoint: string, params: any, me?: any) => { endpoint = endpoint.replace(/^\//, ''); - const auth = me ? { - i: me.token - } : {}; + const auth = me ? { authorization: `Bearer ${me.token}` } : {}; const res = await got(`http://localhost:${port}/api/${endpoint}`, { method: 'POST', headers: { - 'Content-Type': 'application/json' + 'Content-Type': 'application/json', + ...auth, }, - body: JSON.stringify(Object.assign(auth, params)), + body: JSON.stringify(params), retry: { limit: 0, }, @@ -65,16 +64,15 @@ export const api = async (endpoint: string, params: any, me?: any) => { }; export const request = async (endpoint: string, params: any, me?: any): Promise<{ body: any, status: number }> => { - const auth = me ? { - i: me.token, - } : {}; + const auth = me ? { authorization: `Bearer ${me.token}` } : {}; const res = await fetch(`http://localhost:${port}/api${endpoint}`, { method: 'POST', headers: { 'Content-Type': 'application/json', + ...auth, }, - body: JSON.stringify(Object.assign(auth, params)), + body: JSON.stringify(params), }); const status = res.status;