-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3077 from glific/enhancement/maytapi-status
Added notification if maytapi phone is not active
- Loading branch information
Showing
5 changed files
with
151 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 80 additions & 0 deletions
80
src/containers/Chat/ChatMessages/StatusBar/StatusBar.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import { MemoryRouter } from 'react-router'; | ||
import { render, screen, waitFor } from '@testing-library/react'; | ||
import { InMemoryCache } from '@apollo/client'; | ||
import { MockedProvider } from '@apollo/client/testing'; | ||
import { BSPBALANCE } from 'graphql/queries/Organization'; | ||
import { | ||
getInactiveStatusMock, | ||
getWhatsAppManagedPhonesStatusMock, | ||
orgSuspendedMock, | ||
} from 'mocks/StatusBar'; | ||
import StatusBar from './StatusBar'; | ||
|
||
const cache = new InMemoryCache({ | ||
addTypename: false, | ||
}); | ||
|
||
const wrapper = (bspbalance: string, mock?: any) => { | ||
cache.writeQuery({ | ||
query: BSPBALANCE, | ||
variables: { orgId: '1' }, | ||
data: { | ||
bspbalance, | ||
}, | ||
}); | ||
|
||
let MOCKS = [orgSuspendedMock]; | ||
if (mock) { | ||
MOCKS = [...MOCKS, mock]; | ||
} | ||
return ( | ||
<MockedProvider cache={cache} mocks={MOCKS}> | ||
<MemoryRouter initialEntries={['/group/chat']}> | ||
<StatusBar /> | ||
</MemoryRouter> | ||
</MockedProvider> | ||
); | ||
}; | ||
|
||
beforeEach(() => { | ||
cache.reset(); | ||
}); | ||
|
||
test('it should show error message if balance is below 1', async () => { | ||
render(wrapper('{"balance":0.5}', getWhatsAppManagedPhonesStatusMock)); | ||
|
||
await waitFor(() => { | ||
expect(screen.getByTestId('status-bar')).toBeInTheDocument(); | ||
expect( | ||
screen.getByText( | ||
'Please recharge your Gupshup wallet immediately to continue sending messages. Users will not receive the messages that get stuck during this time.' | ||
) | ||
).toBeInTheDocument(); | ||
}); | ||
}); | ||
|
||
test('it should show suspended message if balance is negative', async () => { | ||
render(wrapper('{"balance":-1.4}', getWhatsAppManagedPhonesStatusMock)); | ||
|
||
await waitFor(() => { | ||
expect(screen.getByTestId('status-bar')).toBeInTheDocument(); | ||
expect( | ||
screen.getByText( | ||
'All the outgoing messages have been suspended. Please note: on recharging, the messages that were stuck will not be sent.' | ||
) | ||
).toBeInTheDocument(); | ||
}); | ||
}); | ||
|
||
test('it should show suspended message if balance is negative', async () => { | ||
render(wrapper('{"balance":14.17}', getInactiveStatusMock)); | ||
|
||
await waitFor(() => { | ||
expect(screen.getByTestId('status-bar')).toBeInTheDocument(); | ||
expect( | ||
screen.getByText( | ||
'One or more of your phones are not active. Please check the Maytapi console to ensure smooth message delivery.' | ||
) | ||
).toBeInTheDocument(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { GET_ORGANIZATION_STATUS } from 'graphql/queries/Organization'; | ||
import { GET_WA_MANAGED_PHONES_STATUS } from 'graphql/queries/WaGroups'; | ||
|
||
export const orgSuspendedMock = { | ||
request: { | ||
query: GET_ORGANIZATION_STATUS, | ||
}, | ||
result: { | ||
data: { | ||
organization: { | ||
organization: { | ||
isSuspended: false, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}; | ||
|
||
export const getWhatsAppManagedPhonesStatusMock = { | ||
request: { | ||
query: GET_WA_MANAGED_PHONES_STATUS, | ||
}, | ||
result: { | ||
data: { | ||
waManagedPhones: [ | ||
{ | ||
phone: '918658048983', | ||
status: 'active', | ||
}, | ||
], | ||
}, | ||
}, | ||
}; | ||
|
||
export const getInactiveStatusMock = { | ||
request: { | ||
query: GET_WA_MANAGED_PHONES_STATUS, | ||
variables: {}, | ||
}, | ||
result: { | ||
data: { | ||
waManagedPhones: [ | ||
{ | ||
phone: '918658048983', | ||
status: 'inactive', | ||
}, | ||
], | ||
}, | ||
}, | ||
}; |