From 06eb1e08682ce0251e7ffa7ba3986326ba96c98c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yago=20P=C3=A9rez=20V=C3=A1zquez?= Date: Fri, 20 Oct 2023 16:38:55 +0200 Subject: [PATCH] Add endpoint tests --- packages/api-kit/tests/endpoint/index.test.ts | 60 +++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/packages/api-kit/tests/endpoint/index.test.ts b/packages/api-kit/tests/endpoint/index.test.ts index 1b276107c..04618a81e 100644 --- a/packages/api-kit/tests/endpoint/index.test.ts +++ b/packages/api-kit/tests/endpoint/index.test.ts @@ -564,6 +564,66 @@ describe('Endpoint tests', () => { method: 'get' }) }) + + it('getMessage', async () => { + const safeMessageHash = 'safe-tx-hash' + + await chai + .expect(safeApiKit.getMessage(safeMessageHash)) + .to.be.eventually.deep.equals({ data: { success: true } }) + chai.expect(fetchData).to.have.been.calledWith({ + url: `${txServiceBaseUrl}/v1/messages/${safeMessageHash}/`, + method: 'get' + }) + }) + + it('getMessages', async () => { + const safeAddress = 'safe-address' + + await chai + .expect(safeApiKit.getMessages(safeAddress)) + .to.be.eventually.deep.equals({ data: { success: true } }) + chai.expect(fetchData).to.have.been.calledWith({ + url: `${txServiceBaseUrl}/v1/safes/${safeAddress}/messages/`, + method: 'get' + }) + }) + + it('addMessage', async () => { + const safeAddress = 'safe-address' + const data = { + message: 'message', + signature: '0x' + } + + await chai + .expect(safeApiKit.addMessage(safeAddress, data)) + .to.be.eventually.deep.equals({ data: { success: true } }) + chai.expect(fetchData).to.have.been.calledWith({ + url: `${txServiceBaseUrl}/v1/safes/${safeAddress}/messages/`, + method: 'post', + body: { + ...data, + safeAppId: 0 + } + }) + }) + + it('addMessageSignature', async () => { + const safeMessageHash = 'safe-message-hash' + const signature = '0xSignature' + + await chai + .expect(safeApiKit.addMessageSignature(safeMessageHash, signature)) + .to.be.eventually.deep.equals({ data: { success: true } }) + chai.expect(fetchData).to.have.been.calledWith({ + url: `${txServiceBaseUrl}/v1/messages/${safeMessageHash}/signatures/`, + method: 'post', + body: { + signature + } + }) + }) }) describe('Custom endpoint', () => {