Bugfix: Use server timestamp to set agent_last_seen_at (#1114)

This commit is contained in:
Pranav Raj S
2020-08-03 13:40:20 +05:30
committed by GitHub
parent 941272cccd
commit 3b23aa7913
12 changed files with 62 additions and 26 deletions

View File

@@ -153,4 +153,28 @@ describe('#actions', () => {
expect(commit.mock.calls).toEqual([[types.default.ADD_MESSAGE, message]]);
});
});
describe('#markMessagesRead', () => {
beforeEach(() => {
jest.useFakeTimers();
});
it('sends correct mutations if api is successful', async () => {
const lastSeen = new Date().getTime() / 1000;
axios.post.mockResolvedValue({
data: { id: 1, agent_last_seen_at: lastSeen },
});
await actions.markMessagesRead({ commit }, { id: 1 });
jest.runAllTimers();
expect(commit).toHaveBeenCalledTimes(1);
expect(commit.mock.calls).toEqual([
[types.default.MARK_MESSAGE_READ, { id: 1, lastSeen }],
]);
});
it('sends correct mutations if api is unsuccessful', async () => {
axios.post.mockRejectedValue({ message: 'Incorrect header' });
await actions.markMessagesRead({ commit }, { id: 1 });
expect(commit.mock.calls).toEqual([]);
});
});
});

View File

@@ -20,6 +20,13 @@ describe('#mutations', () => {
{ id: 1, agent_last_seen_at: lastSeen },
]);
});
it('doesnot send any mutation if chat doesnot exist', () => {
const state = { allConversations: [] };
const lastSeen = new Date().getTime() / 1000;
mutations[types.MARK_MESSAGE_READ](state, { id: 1, lastSeen });
expect(state.allConversations).toEqual([]);
});
});
describe('#CLEAR_CURRENT_CHAT_WINDOW', () => {