docbrown/app/javascript/chat/__tests__/chatChannelSettingActions.test.js
narender2031 e78a0078a7
[deploy] Refactor 🚀 : Replaced Chat Channel Setting page with Preact component. (#8271)
* Feature 🚀 : Ability to delete messages in chat channels

- Sending message ID to frontend
- Deleting Message
- Use pusher to delete message realtime

* Minor Bug 🐞: Show message action only for current user

- User can delete or edit their own messages

* Test cases added

* Bug 🐞: Update message id for receiver

Message id was not sent to receiver by pusher

* Refactoring🛠: Message controller refactoring

* Test Cases📝 : Specs for Delete message added

* Feature 🚀 : Ability to edit messages

* Test Cases📝 : Specs for Edit message added

* 🐞 Channel List bug in mobile view

* changes in joining request responses

* 🛠  Request Managers Frontend ready

* changes in routes for adding and removing remembership

* 🚀 New routes implemented for request manager

* fix issues

* changes in api for remove membership

* Merge conflict resolved

* 🐞 Channel List bug in mobile view

* changes in joining request responses

* 🛠  Request Managers Frontend ready

* changes in routes for adding and removing remembership

* 🚀 New routes implemented for request manager

* fix issues

* changes in api for remove membership

* 🛠Optimizing for CodeClimate

* 🛠Optimizing again for CodeClimate

* 🛠Optimizing again 2 for CodeClimate

* 🛠 Added more test cases

* 🛠 Optimizing code

* 🚀 Action to open setting page added

* 🛠  Dummy page added for chat setting

* add JSON routes for chat channel settings

* Integrate chat channel settings API with UI

* 🐞 Channel List bug in mobile view

* 🛠  Request Managers Frontend ready

* changes in routes for adding and removing remembership

* 🚀 New routes implemented for request manager

* fix issues

* 🐞 Channel List bug in mobile view

* 🛠  Request Managers Frontend ready

* changes in routes for adding and removing remembership

* 🚀 New routes implemented for request manager

* fix issues

* 🛠Optimizing again for CodeClimate

* 🚀 Action to open setting page added

* 🛠  Dummy page added for chat setting

* add JSON routes for chat channel settings

* Integrate chat channel settings API with UI

* Fix PR requested changes

* Add JSDoc documentation to exported functions

* fix/add rspec test cases

* refactor channelSettinngs render part

* add test cases for chat channel settings component

* fix code-climate

* add rest component tests

* add more test coverage

* fix code-climate bugs

* add API function test

Co-authored-by: Sarthak Sharma <7lovesharma7@gmail.com>
Co-authored-by: Parasgr-code <paras.gaur@skynox.tech>
2020-06-10 16:58:37 -04:00

203 lines
6 KiB
JavaScript

import fetch from 'jest-fetch-mock';
import {
getChannelDetails,
updatePersonalChatChannelNotificationSettings,
rejectChatChannelJoiningRequest,
acceptChatChannelJoiningRequest,
updateChatChannelDescription,
sendChatChannelInvitation,
leaveChatChannelMembership,
} from '../actions/chat_channel_setting_actions';
/* global globalThis */
describe('Chat cahnnel API requestes', () => {
const csrfToken = 'this-is-a-csrf-token';
const chanChannelMembershipId = 26; // Just a random chatChannelMembershipId ID.
const channelId = 2;
beforeAll(() => {
globalThis.fetch = fetch;
globalThis.getCsrfToken = async () => csrfToken;
});
afterAll(() => {
delete globalThis.fetch;
delete globalThis.getCsrfToken;
});
afterEach(() => {
jest.restoreAllMocks();
});
describe('get chat channel info', () => {
it('should have success response with channel details', async () => {
const response = {
success: true,
current_membership: {
user_id: 1,
id: 2,
chat_channel_id: 1,
status: 'active',
role: 'mod',
},
chat_channel: {
name: 'dummy channel',
description: 'some dummy description',
discoverable: true,
status: 'active',
},
memberships: {
active_memberships: [],
pending_memberships: [],
requested_memberships: [],
},
};
fetch.mockResponse(JSON.stringify(response));
const chatChannelDetails = await getChannelDetails(
chanChannelMembershipId,
);
expect(chatChannelDetails).toEqual(response);
});
it('not found channel', async () => {
const response = {
success: false,
message: 'not found',
};
fetch.mockResponse(JSON.stringify(response));
const chatChannelDetails = await getChannelDetails(
chanChannelMembershipId,
);
expect(chatChannelDetails).toEqual(response);
});
});
describe('Update chat channel notification', () => {
it('should have success', async () => {
const response = { success: true, message: 'user settings updated' };
fetch.mockResponse(JSON.stringify(response));
const updateProfile = await updatePersonalChatChannelNotificationSettings(
chanChannelMembershipId,
true,
);
expect(updateProfile).toEqual(response);
});
it('should return not found error', async () => {
const response = { success: false, message: 'not found' };
fetch.mockResponse(JSON.stringify(response));
const updateProfile = await updatePersonalChatChannelNotificationSettings(
'',
true,
);
expect(updateProfile).toEqual(response);
});
});
describe('reject chat channel membership', () => {
it('should have success', async () => {
const response = { success: true, message: 'user removed' };
fetch.mockResponse(JSON.stringify(response));
const result = await rejectChatChannelJoiningRequest(
channelId,
chanChannelMembershipId,
'pending',
);
expect(result).toEqual(response);
});
it('should return not found error', async () => {
const response = { success: false, message: 'not found' };
fetch.mockResponse(JSON.stringify(response));
const result = await rejectChatChannelJoiningRequest('', '', 'pending');
expect(result).toEqual(response);
});
});
describe('Accept chat channel membership', () => {
it('should have success', async () => {
const response = { success: true, message: 'added to chat channel' };
fetch.mockResponse(JSON.stringify(response));
const result = await acceptChatChannelJoiningRequest(
channelId,
chanChannelMembershipId,
);
expect(result).toEqual(response);
});
it('should return not found error', async () => {
const response = { success: false, message: 'not found' };
fetch.mockResponse(JSON.stringify(response));
const result = await acceptChatChannelJoiningRequest('', '');
expect(result).toEqual(response);
});
});
describe('update chat channel', () => {
it('should have success', async () => {
const response = { success: true, message: 'channel is updated' };
fetch.mockResponse(JSON.stringify(response));
const result = await updateChatChannelDescription(
channelId,
'some description',
true,
);
expect(result).toEqual(response);
});
});
describe('Send inbvitation for join chat channel', () => {
it('should have success', async () => {
const response = { success: true, message: 'added to chat channel' };
fetch.mockResponse(JSON.stringify(response));
const result = await sendChatChannelInvitation(channelId, 'dummyuser');
expect(result).toEqual(response);
});
it('should not send any invitation', async () => {
const response = { success: true, message: 'no invitation sent' };
fetch.mockResponse(JSON.stringify(response));
const result = await sendChatChannelInvitation(channelId, '');
expect(result).toEqual(response);
});
it('should return not found error', async () => {
const response = { success: false, message: 'not found' };
fetch.mockResponse(JSON.stringify(response));
const result = await sendChatChannelInvitation('', '');
expect(result).toEqual(response);
});
});
describe('Leave chat channel', () => {
it('should have success', async () => {
const response = { success: true, message: 'user left the channel' };
fetch.mockResponse(JSON.stringify(response));
const result = await leaveChatChannelMembership(chanChannelMembershipId);
expect(result).toEqual(response);
});
it('should return not found error', async () => {
const response = { success: false, message: 'not found' };
fetch.mockResponse(JSON.stringify(response));
const result = await leaveChatChannelMembership('');
expect(result).toEqual(response);
});
});
});