Skip to content

Commit

Permalink
Merge pull request #734 from Availity/fix/messages-essentials
Browse files Browse the repository at this point in the history
fix(message-core): add essentials rewrite
  • Loading branch information
jordan-a-young authored Aug 14, 2024
2 parents 1e1322e + a27f843 commit 8d66516
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
6 changes: 4 additions & 2 deletions packages/message-core/src/AvMessage.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,13 +103,15 @@ class AvMessage {

domain() {
if (window.location.origin) {
return window.location.origin;
const url = window.location.origin;
return url.replace('essentials', 'apps');
}

if (window.location.hostname) {
return `${window.location.protocol}//${window.location.hostname}${
const url = `${window.location.protocol}//${window.location.hostname}${
window.location.port ? `:${window.location.port}` : ''
}`;
return url.replace('essentials', 'apps');
}

return '*';
Expand Down
20 changes: 18 additions & 2 deletions packages/message-core/src/AvMessage.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import AvMessage from './AvMessage';

let avMessage;
const URL = 'https://dev.local:9999';
const TEST_URL = 'https://dev.local:9999';

describe('AvMessage', () => {
beforeEach(() => {
Expand Down Expand Up @@ -241,7 +241,7 @@ describe('AvMessage', () => {

describe('domain()', () => {
test('should return location.origin if exists', () => {
expect(avMessage.domain()).toBe(URL);
expect(avMessage.domain()).toBe(TEST_URL);
});
});

Expand All @@ -263,6 +263,22 @@ describe('AvMessage', () => {
expect(avMessage.isDomain('hello world')).toBeTruthy();
});

test('domain should return apps.availity.com when window.location.hostname is essentials.availity.com', () => {
const OLD_LOCATION = window.location;

Object.defineProperty(window, 'location', {
value: new URL('https://qa-essentials.availity.com'),
writable: true,
});

expect(avMessage.domain()).toEqual('https://qa-apps.availity.com');

Object.defineProperty(window, 'location', {
value: OLD_LOCATION,
writable: true,
});
});

describe('send', () => {
const testDomain = 'testDomain';
const mockTarget = {
Expand Down

0 comments on commit 8d66516

Please sign in to comment.