diff --git a/.changeset/tender-hounds-breathe.md b/.changeset/tender-hounds-breathe.md new file mode 100644 index 00000000000..a845151cc84 --- /dev/null +++ b/.changeset/tender-hounds-breathe.md @@ -0,0 +1,2 @@ +--- +--- diff --git a/integration/messaging/test/test-send.js b/integration/messaging/test/test-send.js index 06114616b70..7570bdd7d69 100644 --- a/integration/messaging/test/test-send.js +++ b/integration/messaging/test/test-send.js @@ -21,6 +21,7 @@ const sendMessage = require('./utils/sendMessage'); const retrieveToken = require('./utils/retrieveToken'); const seleniumAssistant = require('selenium-assistant'); const getReceivedBackgroundMessages = require('./utils/getReceivedBackgroundMessages'); +const getReceivedForegroundMessages = require('./utils/getReceivedForegroundMessages'); const openNewTab = require('./utils/openNewTab'); const createPermittedWebDriver = require('./utils/createPermittedWebDriver'); @@ -35,6 +36,8 @@ const FIELD_NOTIFICATION = 'notification'; // 4 minutes. The fact that the flow includes making a request to the Send Service, storing/retrieving form indexedDb asynchronously makes these test units to have a execution time variance. Therefore, allowing these units to have a longer time to work is crucial. const TIMEOUT_BACKGROUND_MESSAGE_TEST_UNIT_MILLISECONDS = 240000; +const TIMEOUT_FOREGROUND_MESSAGE_TEST_UNIT_MILLISECONDS = 120000; + // 1 minute. Wait for object store to be created and received message to be stored in idb. This waiting time MUST be longer than the wait time for adding to db in the sw. const WAIT_TIME_BEFORE_RETRIEVING_BACKGROUND_MESSAGES_MILLISECONDS = 60000; @@ -122,6 +125,115 @@ describe('Starting Integration Test > Sending and Receiving ', function() { /* expectedDataPayload= */ getTestDataPayload() ); }); + + it('Foreground app can receive a {} empty message in onMessage', async function() { + this.timeout(TIMEOUT_FOREGROUND_MESSAGE_TEST_UNIT_MILLISECONDS); + + await seleniumAssistant.killWebDriver(globalWebDriver); + + globalWebDriver = createPermittedWebDriver( + /* browser= */ assistantBrowser.getId() + ); + + await globalWebDriver.get( + `${testServer.serverAddress}/${TEST_DOMAIN}/` + ); + + let token = await retrieveToken(globalWebDriver); + checkSendResponse( + await sendMessage({ + to: token + }) + ); + + await checkMessageReceived( + await getReceivedForegroundMessages(globalWebDriver), + /* expectedNotificationPayload= */ null, + /* expectedDataPayload= */ null + ); + }); + + it('Foreground app can receive a {"notification"} message in onMessage', async function() { + this.timeout(TIMEOUT_FOREGROUND_MESSAGE_TEST_UNIT_MILLISECONDS); + + await seleniumAssistant.killWebDriver(globalWebDriver); + + globalWebDriver = createPermittedWebDriver( + /* browser= */ assistantBrowser.getId() + ); + + await globalWebDriver.get( + `${testServer.serverAddress}/${TEST_DOMAIN}/` + ); + + checkSendResponse( + await sendMessage({ + to: await retrieveToken(globalWebDriver), + notification: getTestNotificationPayload() + }) + ); + + await checkMessageReceived( + await getReceivedForegroundMessages(globalWebDriver), + /* expectedNotificationPayload= */ getTestNotificationPayload(), + /* expectedDataPayload= */ null + ); + }); + + it('Foreground app can receive a {"data"} message in onMessage', async function() { + this.timeout(TIMEOUT_FOREGROUND_MESSAGE_TEST_UNIT_MILLISECONDS); + + await seleniumAssistant.killWebDriver(globalWebDriver); + + globalWebDriver = createPermittedWebDriver( + /* browser= */ assistantBrowser.getId() + ); + + await globalWebDriver.get( + `${testServer.serverAddress}/${TEST_DOMAIN}/` + ); + + checkSendResponse( + await sendMessage({ + to: await retrieveToken(globalWebDriver), + data: getTestDataPayload() + }) + ); + + await checkMessageReceived( + await getReceivedForegroundMessages(globalWebDriver), + /* expectedNotificationPayload= */ null, + /* expectedDataPayload= */ getTestDataPayload() + ); + }); + + it('Foreground app can receive a {"notification", "data"} message in onMessage', async function() { + this.timeout(TIMEOUT_FOREGROUND_MESSAGE_TEST_UNIT_MILLISECONDS); + + await seleniumAssistant.killWebDriver(globalWebDriver); + + globalWebDriver = createPermittedWebDriver( + /* browser= */ assistantBrowser.getId() + ); + + await globalWebDriver.get( + `${testServer.serverAddress}/${TEST_DOMAIN}/` + ); + + checkSendResponse( + await sendMessage({ + to: await retrieveToken(globalWebDriver), + data: getTestDataPayload(), + notification: getTestNotificationPayload() + }) + ); + + await checkMessageReceived( + await getReceivedForegroundMessages(globalWebDriver), + /* expectedNotificationPayload= */ getTestNotificationPayload(), + /* expectedDataPayload= */ getTestDataPayload() + ); + }); }); }); });