docbrown/app/javascript/chat/__tests__/chatChannelSettingActions.test.js
Sarthak Sharma 3addb64326
[deploy] 🚀 Feature: Chat channel membership manager component (#8945)
* 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

* Merge conflict resolved

* fix video content issue

* add UI for membership management

* add api to update memberahip role

* add methods for manage membership

* Add integration test cases

* add emoji for admin

* Open member profile in sidecar only

* 🐞 Problem with direct channel sidecar

* 🐞 Few other UI enhancements

* fix mod typo

* add limit upto 4 for display active memberships

* fix UI issues

* fix action ui for membership

* fix sidebar redirection issue

* fix svg buttons

* add test cases

* fixed broken spec

* fix PR suggestions

* remove not used code

* fix typo

* fix PR suggestion

* fix typos

* add invitation url expiry

* fix specs

* fix PR suggestions

* removed unused gem

* remove presenter format

* handle invitation link expiry with redis

* fix PR suggestions

* user can view non-discoverable channel invitation link

* fix typos

* remove commented code

* add spacing

* PR suggestions

* remove class from button

* replace componentDidMount with commen function

* remove action button for single membership

* add chat message on update role

* add spece between lines

Co-authored-by: Narender Singh <narender2031@gmail.com>
Co-authored-by: Fernando Valverde <fdov88@gmail.com>
2020-07-20 08:08:31 -04:00

226 lines
6.7 KiB
JavaScript

import fetch from 'jest-fetch-mock';
import {
getChannelDetails,
updatePersonalChatChannelNotificationSettings,
rejectChatChannelJoiningRequest,
acceptChatChannelJoiningRequest,
updateChatChannelDescription,
sendChatChannelInvitation,
leaveChatChannelMembership,
updateMembershipRole,
} 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);
});
});
describe('Update the membership role', () => {
it('should have the success response', async () => {
const response = { success: true, message: 'user membership is updated' };
fetch.mockResponse(JSON.stringify(response));
const result = await updateMembershipRole(
chanChannelMembershipId,
channelId,
'mod',
);
expect(result).toEqual(response);
});
it('should return the not found', async () => {
const response = { success: false, message: 'not found' };
fetch.mockResponse(JSON.stringify(response));
const result = await updateMembershipRole('', '', 'mod');
expect(result).toEqual(response);
});
});
});