Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
182 changes: 0 additions & 182 deletions __tests__/android/__snapshots__/app-gradle-build.test.js.snap

This file was deleted.

46 changes: 0 additions & 46 deletions __tests__/android/__snapshots__/app-manifest.test.js.snap

This file was deleted.

48 changes: 0 additions & 48 deletions __tests__/android/__snapshots__/main-gradle-build.test.js.snap

This file was deleted.

19 changes: 10 additions & 9 deletions __tests__/android/app-gradle-build.test.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
const fs = require("fs-extra");
const path = require("path");
const { getTestPaths } = require("../helpers/testConfig");
const { parseGradleFile } = require("../helpers/parsers");

const testProjectPath = path.join(__dirname, "../../test-app");
const androidPath = path.join(testProjectPath, "android");
const appBuildGradlePath = path.join(androidPath, "app/build.gradle");
describe('Android Gradle Customizations', () => {
const { appBuildGradlePath } = getTestPaths();

test("Plugin applies Google Services plugin in the app Gradle build file", async () => {
const content = await fs.readFile(appBuildGradlePath, "utf8");

expect(content).toMatchSnapshot();
test("Plugin applies Google Services plugin in the app Gradle build file", async () => {
const gradleFileAsJson = await parseGradleFile(appBuildGradlePath);

// Using our custom matcher
expect(gradleFileAsJson).toHaveGoogleServicesPlugin();
});
});
38 changes: 27 additions & 11 deletions __tests__/android/app-manifest.test.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,30 @@
const fs = require("fs-extra");
const path = require("path");
const { getTestPaths } = require("../helpers/testConfig");
const { parseAndroidManifest } = require("../helpers/parsers");

const testProjectPath = path.join(__dirname, "../../test-app");
const androidPath = path.join(testProjectPath, "android");
const appManifestPath = path.join(androidPath, "app/src/main/AndroidManifest.xml");
describe('Android Manifest Customizations', () => {
const { appManifestPath } = getTestPaths();

test("Plugin injects CustomerIOFirebaseMessagingService in the app manifest", async () => {
// When setHighPriorityPushHandler config is set to true when setting up the plugin
// an intent filter for CustomerIOFirebaseMessagingService is added to the app Manifest file
const content = await fs.readFile(appManifestPath, "utf8");

expect(content).toMatchSnapshot();
test("Plugin injects CustomerIOFirebaseMessagingService in the app manifest", async () => {
// When setHighPriorityPushHandler config is set to true when setting up the plugin
// an intent filter for CustomerIOFirebaseMessagingService is added to the app Manifest file
const manifest = await parseAndroidManifest(appManifestPath);

// Using our custom matcher
expect(manifest).toHaveCIOFirebaseService();

// The custom matcher above replaces all these individual assertions:
// const expectedServiceName = 'io.customer.messagingpush.CustomerIOFirebaseMessagingService';
// const expectedAction = 'com.google.firebase.MESSAGING_EVENT';
// const application = manifest?.manifest?.application?.[0];
// expect(application).toBeDefined();
// const services = application.service || [];
// const service = services.find(service => service['$']['android:name'] === expectedServiceName);
// expect(service).toBeDefined();
// expect(service['$']['android:exported']).toBe('false');
// expect(service['intent-filter']).toBeDefined();
// expect(service['intent-filter'].length).toBeGreaterThan(0);
// const actions = service['intent-filter'][0].action || [];
// const hasExpectedAction = actions.some(action => action['$']['android:name'] === expectedAction);
// expect(hasExpectedAction).toBe(true);
});
});
29 changes: 21 additions & 8 deletions __tests__/android/main-gradle-build.test.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,25 @@
const fs = require("fs-extra");
const path = require("path");
const { getTestPaths } = require("../helpers/testConfig");
const { parseGradleFile } = require("../helpers/parsers");
const fs = require('fs-extra');

const testProjectPath = path.join(__dirname, "../../test-app");
const androidPath = path.join(testProjectPath, "android");
const mainBuildGradlePath = path.join(androidPath, "build.gradle");
describe('Android Project Gradle Customizations', () => {
const { mainBuildGradlePath } = getTestPaths();

test("Plugin injects expted dependencies in the main Gradle build file", async () => {
const content = await fs.readFile(mainBuildGradlePath, "utf8");
test('Plugin injects expected dependencies in the main Gradle build file', async () => {
const mainBuildGradleContent = await fs.readFile(mainBuildGradlePath, "utf8");
const gradleFileAsJson = await parseGradleFile(mainBuildGradlePath);

expect(content).toMatchSnapshot();
// Check for Google Services classpath dependency
const hasBuildScriptDependency = gradleFileAsJson.buildscript.dependencies.some(
(dependency) =>
dependency.group === 'com.google.gms' &&
dependency.name === 'google-services' &&
dependency.type === 'classpath'
);

expect(hasBuildScriptDependency).toBe(true);

// Check for Gist maven repository
expect(mainBuildGradleContent).toContain('maven { url "https://maven.gist.build" }');
});
});
Loading