From 381a5be119cf10409614c1df79220c4dba263b33 Mon Sep 17 00:00:00 2001 From: rubeniskov Date: Wed, 23 Dec 2020 13:34:15 +0100 Subject: [PATCH] test(@cuser/client): update specs testing --- packages/client/client.test.js | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/packages/client/client.test.js b/packages/client/client.test.js index 90a4548..9dd121c 100644 --- a/packages/client/client.test.js +++ b/packages/client/client.test.js @@ -7,7 +7,7 @@ const md5 = (data) => crypto.createHash('md5').update(typeof data === 'string' ? test.beforeEach((t) => { const domain = 'example.com'; - const hostname = `http://${domain}` + const hostname = `https://${domain}` const parseCid = sinon.spy(a => a); const cuserId = 'QmZFZMK6wMDvWCTwq5S1Wz7fRtZJayebxAPGkRttTV1V1f'; const fetch = sinon.spy(() => Promise.resolve({ @@ -40,7 +40,7 @@ test('should guess url when global.location defined', async (t) => { }); test('should send POST request when using publishMessage', async (t) => { - const { node, address, topicId, opts } = t.context; + const { node, address, hostname, topicId, opts } = t.context; const { fetch } = opts; const accessToken = 'randomAccessToken'; const content = 'this is a test message'; @@ -49,7 +49,7 @@ test('should send POST request when using publishMessage', async (t) => { await client.publishMessage(topicId, accessToken, 'this is a test message'); t.deepEqual(fetch.args[0], [ - 'http://example.com/api/v0/rest/message',{ + `${hostname}/api/v0/rest/message`,{ method: 'POST', body: `{"topicId":"${topicId}","content":"${content}"}`, headers: { Authorization: accessToken } @@ -58,7 +58,7 @@ test('should send POST request when using publishMessage', async (t) => { }); test('should send PATCH request when using updateMessage', async (t) => { - const { node, address, topicId, opts } = t.context; + const { node, address, hostname, topicId, opts } = t.context; const { fetch } = opts; const accessToken = 'randomAccessToken'; const messageId = 'message_id'; @@ -67,7 +67,7 @@ test('should send PATCH request when using updateMessage', async (t) => { await client.updateMessage(topicId, accessToken, messageId); t.deepEqual(fetch.args[0], [ - 'http://example.com/api/v0/rest/message',{ + `${hostname}/api/v0/rest/message`,{ method: 'PATCH', body: `{"topicId":"${topicId}","messageId":"${messageId}"}`, headers: { Authorization: accessToken } @@ -76,7 +76,7 @@ test('should send PATCH request when using updateMessage', async (t) => { }); test('should send DELETE request when using deleteMessage', async (t) => { - const { node, address, topicId, opts } = t.context; + const { node, address, hostname, topicId, opts } = t.context; const { fetch } = opts; const accessToken = 'randomAccessToken'; const messageId = 'message_id'; @@ -85,7 +85,7 @@ test('should send DELETE request when using deleteMessage', async (t) => { await client.deleteMessage(topicId, accessToken, messageId); t.deepEqual(fetch.args[0], [ - 'http://example.com/api/v0/rest/message',{ + `${hostname}/api/v0/rest/message`,{ method: 'DELETE', body: `{"topicId":"${topicId}","messageId":"${messageId}"}`, headers: { Authorization: accessToken } @@ -94,16 +94,16 @@ test('should send DELETE request when using deleteMessage', async (t) => { }); test('should send POST request when using authenticate', async (t) => { - const { node, address, cuserId, opts } = t.context; + const { node, address, hostname, cuserId, opts } = t.context; const { fetch } = opts; const username = 'bob'; - const avatar = 'http://example.com/avatar'; + const avatar = '${hostname}/avatar'; const client = createClient(node, address, opts); await client.authenticate(username, avatar) t.deepEqual(fetch.args[0], [ - 'http://example.com/api/v0/auth',{ + `${hostname}/api/v0/auth`,{ method: 'POST', body: `{"peerId":"${cuserId}","username":"${username}","avatar":"${avatar}"}` }