docbrown/app/javascript/utilities/__tests__/getUserDataAndCsrfToken.test.js
Michael Kohl 09828853f6
✂✂✂ Remove Connect (#14734)
* Remove Connect

* Remove more Connect specs

* Remove a lot more Connect code

* 🚮

* It all has to go

* Explicitly add httpclient

* Update application layout

* Remove messages association from User

* Start fixing specs

* reintroduce util function and refactor references

* Remove Connect Cypress test

* Fix more specs

* Remove Connect from listings

* Ignore contact_via_connect column on listings

* Remove contact_via_connect usages

* Ignore mod_chat_channel_id on tags

* Drop Connect tables

* Remove email_connect_messages from user notification settings

* Re-add httpclient 2.8.3

This was mistakenly removed as a merge conflict

* Don't need to exclude removed chat channel file

* Remove unneeded style for chat channels

* Remove unneeded channel list prop type

* Remove chat channels index/connect-link from getPageEntries

* Re-add comment from httpclient in Gemfile

* Remove connect references from mailers

Tag Moderators no longer have a chat channel

No longer will users be notified about new messages (there won't be
any)

No longer will users be notified about channel invites (you can't
invite anyone anymore)

* Don't configure Pusher and remove PUSHER_* from .env_sample

since it's removed from gemfile, the Pusher constant will not resolve, if this is
configured in the environment variables we'll fail to boot.

Co-authored-by: Suzanne Aitchison <suzanne@forem.com>
Co-authored-by: Dan Uber <dan@forem.com>
2021-11-18 08:21:00 -06:00

56 lines
1.7 KiB
JavaScript

import { getUserDataAndCsrfToken } from '../getUserDataAndCsrfToken';
const ERROR_MESSAGE = "Couldn't find user data on page.";
describe('getUserDataAndCsrfToken', () => {
afterEach(() => {
document.head.innerHTML = '';
document.body.removeAttribute('data-user');
});
test('should reject if no user or csrf token found.', async () => {
await expect(getUserDataAndCsrfToken(document)).rejects.toThrow(
ERROR_MESSAGE,
);
});
test('should reject if csrf token found but no user.', async () => {
document.head.innerHTML =
'<meta name="csrf-token" content="some-csrf-token" />';
await expect(getUserDataAndCsrfToken(document)).rejects.toThrow(
ERROR_MESSAGE,
);
});
test('should reject if user found but no csrf token found.', async () => {
document.body.setAttribute('data-user', '{}');
await expect(getUserDataAndCsrfToken(document)).rejects.toThrow(
ERROR_MESSAGE,
);
});
test('should resolve if user and csrf token found.', async () => {
const csrfToken = 'some-csrf-token';
const currentUser = {
id: 41,
name: 'Guy Fieri',
username: 'guyfieri',
profile_image_90:
'/uploads/user/profile_image/41/0841dbe2-208c-4daa-b498-b2f01f3d37b2.png',
followed_tag_names: [],
followed_tags: '[]',
reading_list_ids: [48, 49, 34, 51, 64, 56],
saw_onboarding: true,
checked_code_of_conduct: false,
display_sponsors: true,
trusted: false,
};
document.head.innerHTML = `<meta name="csrf-token" content="${csrfToken}" />`;
document.body.setAttribute('data-user', JSON.stringify(currentUser));
expect(await getUserDataAndCsrfToken(document)).toEqual({
currentUser,
csrfToken,
});
});
});