From aa723051f64cbcad69d0bc8eebd8b3434d72fb25 Mon Sep 17 00:00:00 2001 From: Andre Christoga Pramaditya Date: Fri, 27 May 2022 13:44:09 +0700 Subject: [PATCH] feat(jest): 100% branch coverage for store/friends/mutations --- .../__snapshots__/mutations.test.ts.snap | 79 +++++++++++++- store/friends/mutations.test.ts | 101 +++++++++++++++++- 2 files changed, 177 insertions(+), 3 deletions(-) diff --git a/store/friends/__snapshots__/mutations.test.ts.snap b/store/friends/__snapshots__/mutations.test.ts.snap index 68628caff6..88d7b4dfef 100644 --- a/store/friends/__snapshots__/mutations.test.ts.snap +++ b/store/friends/__snapshots__/mutations.test.ts.snap @@ -133,7 +133,53 @@ Array [ "name": "Yusuf Mangunwijaya", "stored": false, "textilePubkey": "https://accounts.google.com/o/oauth2/revoke?token=429", - "typingState": "TYPING", + "typingState": undefined, + }, +] +`; + +exports[`mutate friends set typing state but non-identical address 1`] = ` +Array [ + Object { + "account": Object { + "accountId": "Checking Account", + "from": ".", + "fromMailboxId": "12345", + "status": 429, + "to": "./path/to/file", + "toMailboxId": "v4.0.0-rc.4", + }, + "address": "0xdf9eb223bafbe5c5271415c75aecd68c21fe3d7f", + "badge": "community", + "encryptedTextilePubkey": "", + "item": Object {}, + "mailboxId": "", + "name": "Taurus Nix", + "pending": true, + "profilePicture": "", + "publicKey": "NoWiFi4you", + "state": "idle", + "status": "", + "stored": undefined, + "textilePubkey": "https://accounts.google.com/o/oauth2/revoke?token=%s", + "typingState": "NOT_TYPING", + "unreadCount": 123, + "userAccount": "", + }, + Object { + "account": Object { + "accountId": "Checking Account", + "from": ".", + "fromMailboxId": "12345", + "status": 429, + "to": "./path/to/file", + "toMailboxId": "v4.0.0-rc.4", + }, + "address": "0x1", + "name": "Yusuf Mangunwijaya", + "stored": false, + "textilePubkey": "https://accounts.google.com/o/oauth2/revoke?token=429", + "typingState": "NOT_TYPING", }, ] `; @@ -264,6 +310,37 @@ Array [ ] `; +exports[`mutations.setNote real but non-identical id 1`] = ` +Array [ + Object { + "account": Object { + "accountId": "Checking Account", + "from": ".", + "fromMailboxId": "12345", + "status": 429, + "to": "./path/to/file", + "toMailboxId": "v4.0.0-rc.4", + }, + "activeChat": true, + "address": "0xdf9eb223bafbe5c5271415c75aecd68c21fe3d7f", + "badge": "community", + "encryptedTextilePubkey": "", + "item": Object {}, + "localSypingState": "NOT_TYPING", + "mailboxId": "", + "name": "Taurus Nix", + "pending": true, + "profilePicture": "", + "publicKey": "NoWiFi4you", + "state": "idle", + "status": "", + "textilePubkey": "https://accounts.google.com/o/oauth2/revoke?token=%s", + "unreadCount": 123, + "userAccount": "", + }, +] +`; + exports[`mutations.setStored 0 1`] = `undefined`; exports[`mutations.setStored 1 1`] = `undefined`; diff --git a/store/friends/mutations.test.ts b/store/friends/mutations.test.ts index 6182db08c7..6599ab2175 100644 --- a/store/friends/mutations.test.ts +++ b/store/friends/mutations.test.ts @@ -510,7 +510,7 @@ describe('mutate friends', () => { const payload: any = { name: 'Yusuf Mangunwijaya', address: '0x1', // We will just use this - typingState: 'TYPING', // Change the value here so we can detect it in the the expect() below + typingState: 'NOT_TYPING', // Change the value here so we can detect it in the the expect() below account: { accountId: 'Checking Account', from: '.', @@ -524,7 +524,29 @@ describe('mutate friends', () => { inst.setTyping(InitialFriendsState, { id: payload.address, - typingState: 'TYPING', + // typingState: 'TYPING', + }) + expect(InitialFriendsState.all).toMatchSnapshot() + }) + test('set typing state but non-identical address', () => { + const payload: any = { + name: 'Yusuf Mangunwijaya', + address: '0x1', // We will just use this + typingState: 'TYPING', // Change the value here so we can detect it in the the expect() below + account: { + accountId: 'Checking Account', + from: '.', + status: 429, + fromMailboxId: '12345', + toMailboxId: 'v4.0.0-rc.4', + to: './path/to/file', + }, + textilePubkey: 'https://accounts.google.com/o/oauth2/revoke?token=429', + } + + inst.setTyping(InitialFriendsState, { + id: '0x2', // 0x2 rather than 0x1 + typingState: undefined, }) expect(InitialFriendsState.all).toMatchSnapshot() }) @@ -1103,6 +1125,81 @@ describe('mutations.setNote', () => { mutations.setNote(localState, argument) expect(localState.all).toMatchSnapshot() }) + test('real but non-identical id', () => { + const localState = { + incomingRequests: [ + { + requestId: 'incomingRequestsItem0', + account: { + accountId: '', + from: '', + status: 123, + fromMailboxId: '', + toMailboxId: '', + to: '', + }, + pending: true, + from: '', + userInfo: { + name: '', + servers: {}, + status: '', + photoHash: '', + }, + }, + ], + outgoingRequests: [ + { + to: '', + requestId: '', + account: { + accountId: '', + from: '', + status: 123, + fromMailboxId: '', + toMailboxId: '', + to: '', + }, + pending: true, + }, + ], + all: [ + { + publicKey: 'NoWiFi4you', + localSypingState: 'NOT_TYPING', + item: {}, + pending: true, + activeChat: true, + encryptedTextilePubkey: '', + name: 'Taurus Nix', + address: '0xdf9eb223bafbe5c5271415c75aecd68c21fe3d7f', + account: { + accountId: 'Checking Account', + from: '.', + status: 429, + fromMailboxId: '12345', + toMailboxId: 'v4.0.0-rc.4', + to: './path/to/file', + }, + textilePubkey: 'https://accounts.google.com/o/oauth2/revoke?token=%s', + status: '', + state: 'idle', + unreadCount: 123, + profilePicture: '', + badge: 'community', + userAccount: '', + mailboxId: '', + }, + ], + } + const argument = { + id: '1xdf9eb223bafbe5c5271415c75aecd68c21fe3d7f', // 1x rather than 0x + note: 'zeroxzero', + } + + mutations.setNote(localState, argument) + expect(localState.all).toMatchSnapshot() + }) test('0', () => { const result: any = mutations.setNote(