forked from FoundKeyGang/FoundKey
tests: use bearer authentication
This commit is contained in:
parent
605a55e1d4
commit
eecff514c2
1 changed files with 7 additions and 9 deletions
|
@ -31,16 +31,15 @@ export const async = (fn: Function) => (done: Function) => {
|
||||||
export const api = async (endpoint: string, params: any, me?: any) => {
|
export const api = async (endpoint: string, params: any, me?: any) => {
|
||||||
endpoint = endpoint.replace(/^\//, '');
|
endpoint = endpoint.replace(/^\//, '');
|
||||||
|
|
||||||
const auth = me ? {
|
const auth = me ? { authorization: `Bearer ${me.token}` } : {};
|
||||||
i: me.token
|
|
||||||
} : {};
|
|
||||||
|
|
||||||
const res = await got<string>(`http://localhost:${port}/api/${endpoint}`, {
|
const res = await got<string>(`http://localhost:${port}/api/${endpoint}`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json'
|
'Content-Type': 'application/json',
|
||||||
|
...auth,
|
||||||
},
|
},
|
||||||
body: JSON.stringify(Object.assign(auth, params)),
|
body: JSON.stringify(params),
|
||||||
retry: {
|
retry: {
|
||||||
limit: 0,
|
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 }> => {
|
export const request = async (endpoint: string, params: any, me?: any): Promise<{ body: any, status: number }> => {
|
||||||
const auth = me ? {
|
const auth = me ? { authorization: `Bearer ${me.token}` } : {};
|
||||||
i: me.token,
|
|
||||||
} : {};
|
|
||||||
|
|
||||||
const res = await fetch(`http://localhost:${port}/api${endpoint}`, {
|
const res = await fetch(`http://localhost:${port}/api${endpoint}`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
|
...auth,
|
||||||
},
|
},
|
||||||
body: JSON.stringify(Object.assign(auth, params)),
|
body: JSON.stringify(params),
|
||||||
});
|
});
|
||||||
|
|
||||||
const status = res.status;
|
const status = res.status;
|
||||||
|
|
Loading…
Reference in a new issue