Skip to content

Commit

Permalink
feat(jest): 100% branch coverage for store/friends/mutations (#3322)
Browse files Browse the repository at this point in the history
  • Loading branch information
drepram committed May 27, 2022
1 parent db5a351 commit da83d48
Show file tree
Hide file tree
Showing 2 changed files with 177 additions and 3 deletions.
79 changes: 78 additions & 1 deletion store/friends/__snapshots__/mutations.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -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",
},
]
`;
Expand Down Expand Up @@ -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`;
Expand Down
101 changes: 99 additions & 2 deletions store/friends/mutations.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: '.',
Expand All @@ -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()
})
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit da83d48

Please sign in to comment.