Skip to content

Commit

Permalink
[release note] - [feature-instance] --> sub feature complete "Subscribe"
Browse files Browse the repository at this point in the history
  • Loading branch information
syedahmedjamil committed Jan 10, 2024
1 parent 5e968cf commit 7ae812f
Show file tree
Hide file tree
Showing 50 changed files with 993 additions and 160 deletions.
1 change: 1 addition & 0 deletions .github/workflows/dev-push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ on:
push:
paths-ignore:
- '.github/**'
- 'README.md'
branches: [ "dev" ]

jobs:
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/main-push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ on:
push:
paths-ignore:
- '.github/**'
- 'README.md'
branches: [ "main" ]

workflow_dispatch:
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ local.properties
.gradle
build
pusher-notif.txt
*.jks
*.jks
.aiexclude
37 changes: 4 additions & 33 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,40 +1,11 @@
# Update
Rewriting app with clean architecture, acceptance test driven development and continous integration/delivery using Github Actions and Firebase App Distribution.
To access the old version, navigate to this [commit](https://github.com/syedahmedjamil/pushier/commit/ea7f30f8890fba63ff5571d64c3dffbe08dd9bfd) and click "Browse Files".
Updating app using clean architecture, acceptance test driven development and continuous integration/delivery using Github Actions and Firebase App Distribution. To see the old version, navigate to this [commit](https://github.com/syedahmedjamil/pushier/commit/ea7f30f8890fba63ff5571d64c3dffbe08dd9bfd) and click "Browse Files".

# About
Android client app that integrates with pusher beams to show realtime in-app notifications.

# Before building the app
1. configure fcm https://pusher.com/docs/beams/getting-started/android/configure-fcm/?ref=docs-index#open-firebase-console
2. make sure when creating app in firebase the **"Android package name"** is same as you set in **build.grade** `applicationId`
3. paste your fcm server key in your pusher beams instance "Settings" page under "Google FCM Integration" field
4. download and store your `google-services.json` file in the app folder
# Tests (new)
![](https://github.com/syedahmedjamil/pushier/blob/main/extras/tests.gif)

# Payload
> NOTE: your interest name has to be present in the `interests` array as well as in `fcm.data.interest` as shown below for it to work properly.
```json
{
"interests": [
"reddit"
],
"fcm": {
"data": {
"interest": "reddit",
"category": "Important",
"date": "1/1/2022",
"title": "How to optimise text size on lower dpi devices",
"body": "In XML, is there any other way than defining new layouts files for different dpi devices just to handle text sizes as it completely messes up the entire layout if not handled properly?",
"subtext": "r/androiddev",
"link": "https://www.reddit.com/r/androiddev/comments/13a3p1c/how_to_optimise_text_size_on_lower_dpi_devices",
"image": "https://media.glassdoor.com/sql/796358/reddit-squarelogo-1490630845152.png"
}
}
}
```
Sample using curl is located in : https://github.com/syedahmedjamil/pushier/blob/main/extras/payload%20sample%20using%20curl.bat.

To use this sample you will need `PUSHER-BEAMS-INSTANCE-PRIMARY-KEY` and `PUSHER-BEAMS-INSTANCE-ID` both of which can be found by going to the "Keys" page of your pusher beams instance

# Demo
# Demo (old)
![](https://github.com/syedahmedjamil/pushier/blob/main/extras/demo.gif)
3 changes: 2 additions & 1 deletion app/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
.gradle
*.jks
*.json
misc
misc
.aiexclude
15 changes: 12 additions & 3 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ plugins {
id("com.google.gms.google-services")
id("com.google.firebase.crashlytics")
id("com.google.firebase.appdistribution")
id("androidx.navigation.safeargs.kotlin")
}
val keystorePropertiesFile = rootProject.file("app/keystore.properties")
val keystoreProperties = Properties()
Expand All @@ -22,7 +23,7 @@ android {
minSdk = 24
targetSdk = 33
versionCode = project.property("versionCode").toString().toInt()
versionName = "1.0.0"
versionName = "1.2.0"
testApplicationId = "com.github.syedahmedjamil.pushernotif.test"
//testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
testInstrumentationRunner = "io.cucumber.android.runner.CucumberAndroidJUnitRunner"
Expand Down Expand Up @@ -107,6 +108,12 @@ android {
implementation(libs.androidx.constraintlayout)
implementation("androidx.datastore:datastore-preferences:1.0.0")
implementation("androidx.lifecycle:lifecycle-livedata-ktx:2.6.2") // for asLiveData method
implementation("com.google.firebase:firebase-iid:21.1.0")
implementation(platform("com.google.firebase:firebase-bom:32.7.0"))
implementation("com.google.firebase:firebase-messaging")
implementation("com.pusher:push-notifications-android:1.9.2")
implementation("androidx.navigation:navigation-ui-ktx:2.7.6")
implementation("androidx.navigation:navigation-fragment-ktx:2.7.6")

//test
testImplementation(project(":shared-test"))
Expand All @@ -119,8 +126,10 @@ android {
androidTestImplementation(libs.androidx.junit)
androidTestImplementation(libs.androidx.espresso.core)
androidTestImplementation(libs.cucumber.android)
androidTestImplementation(libs.androidx.rules)
androidTestImplementation("org.jetbrains.kotlinx:kotlinx-coroutines-test:1.7.3")

androidTestImplementation("com.squareup.okhttp3:okhttp:3.12.0")
androidTestImplementation("androidx.test.uiautomator:uiautomator:2.3.0-alpha03")
}

}
}
1 change: 1 addition & 0 deletions app/src/androidTest/assets/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
test.properties
30 changes: 30 additions & 0 deletions app/src/androidTest/assets/features/instance/subscribe.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
Feature: Subscribe
User subscribes to a pusher instance using instance id

Background:
Given I am on the "Instance" screen

Scenario: User subscribes with empty instance id
Given I set "" as instance id
When I try to subscribe
Then I should see message "Please enter your Pusher Instance ID."

Scenario: User subscribes with empty interests
Given I set "00000000-0000-0000-0000-000000000000" as instance id
When I try to subscribe
Then I should see message "Please add at least 1 interest before subscribing."

Scenario: User subscribes with no internet access
Given Internet connection is turned "off"
And I set "00000000-0000-0000-0000-000000000000" as instance id
And I add "test" as an interest
When I try to subscribe
Then I should see message "Network unavailable."

Scenario: User subscribes with valid data and internet access
Given Internet connection is turned "on"
And I set "00000000-0000-0000-0000-000000000000" as instance id
And I add "test" as an interest
When I try to subscribe
Then I am on the "Notifications" screen

Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,22 @@ import androidx.test.core.app.ActivityScenario
import androidx.test.core.app.ApplicationProvider
import com.github.syedahmedjamil.pushernotif.MyApplication
import com.github.syedahmedjamil.pushernotif.test.dsl.CucumberDsl
import com.github.syedahmedjamil.pushernotif.ui.instance.InstanceActivity
import com.github.syedahmedjamil.pushernotif.ui.MainActivity
import io.cucumber.java.After
import io.cucumber.java.Before
import io.cucumber.java.en.Given
import io.cucumber.java.en.Then
import io.cucumber.java.en.When
import io.cucumber.java.PendingException
import io.cucumber.java.en.And

class FeatureInstanceSteps {
private val dsl = CucumberDsl()

private lateinit var activityScenario: ActivityScenario<InstanceActivity>
private lateinit var activityScenario: ActivityScenario<MainActivity>

@Before
fun setup() {
activityScenario = ActivityScenario.launch(InstanceActivity::class.java)
activityScenario = ActivityScenario.launch(MainActivity::class.java)
}

@After
Expand All @@ -31,7 +30,7 @@ class FeatureInstanceSteps {

@Given("I am on the {string} screen")
fun iAmOnThePage(arg0: String) {
dsl.instance.assertTitle(arg0)
dsl.instance.assertScreenTitle(arg0)
}

@When("I add {string} as an interest")
Expand All @@ -58,4 +57,20 @@ class FeatureInstanceSteps {
fun iShouldNotSeeAsAnInterest(arg0: String) {
dsl.instance.assertInterestNotListed(arg0)
}

@Given("I set {string} as instance id")
fun iSetAsInstanceId(arg0: String) {
dsl.instance.setInstanceId(arg0)
}

@When("I try to subscribe")
fun iTryToSubscribe() {
dsl.instance.subscribe()

}

@Given("Internet connection is turned {string}")
fun internetConnectionIsTurned(arg0: String) {
dsl.instance.setInternetConnection(arg0)
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
package com.github.syedahmedjamil.pushernotif
package com.github.syedahmedjamil.pushernotif.test.integration

import android.content.Context
import androidx.test.core.app.ApplicationProvider
import com.github.syedahmedjamil.pushernotif.AppContainer
import com.github.syedahmedjamil.pushernotif.usecases.AddInterestUseCase
import com.github.syedahmedjamil.pushernotif.usecases.GetInterestsUseCase
import com.github.syedahmedjamil.pushernotif.usecases.RemoveInterestUseCase
import org.junit.Assert.assertEquals
import org.junit.Assert.assertNotEquals
import org.junit.Assert.assertNotNull
import org.junit.Assert.assertTrue
import com.github.syedahmedjamil.pushernotif.usecases.SubscribeUseCase
import org.junit.Assert
import org.junit.Test

class AppContainerTest {
Expand All @@ -18,30 +17,38 @@ class AppContainerTest {

@Test
fun test_appContainer_is_not_null() {
assertNotNull(appContainer)
Assert.assertNotNull(appContainer)
}

@Test
fun test_appContainer_has_a_addInterestUseCase_singleton() {
val useCase1: AddInterestUseCase = appContainer.addInterestUseCase
val useCase2: AddInterestUseCase = appContainer.addInterestUseCase
assertNotNull(useCase1)
assertEquals(useCase1, useCase2)
Assert.assertNotNull(useCase1)
Assert.assertEquals(useCase1, useCase2)
}

@Test
fun test_appContainer_has_a_getInterestsUseCase_singleton() {
val useCase1: GetInterestsUseCase = appContainer.getInterestsUseCase
val useCase2: GetInterestsUseCase = appContainer.getInterestsUseCase
assertNotNull(useCase1)
assertEquals(useCase1, useCase2)
Assert.assertNotNull(useCase1)
Assert.assertEquals(useCase1, useCase2)
}

@Test
fun test_appContainer_has_a_removeInterestUseCase_singleton() {
val useCase1: RemoveInterestUseCase = appContainer.removeInterestUseCase
val useCase2: RemoveInterestUseCase = appContainer.removeInterestUseCase
assertNotNull(useCase1)
assertEquals(useCase1, useCase2)
Assert.assertNotNull(useCase1)
Assert.assertEquals(useCase1, useCase2)
}

@Test
fun test_appContainer_has_a_subscribeUseCase_singleton() {
val useCase1: SubscribeUseCase = appContainer.subscribeUseCase
val useCase2: SubscribeUseCase = appContainer.subscribeUseCase
Assert.assertNotNull(useCase1)
Assert.assertEquals(useCase1, useCase2)
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.github.syedahmedjamil.pushernotif
package com.github.syedahmedjamil.pushernotif.test.integration

import android.content.Context
import androidx.datastore.core.DataStore
Expand All @@ -20,7 +20,7 @@ import kotlinx.coroutines.test.TestScope
import kotlinx.coroutines.test.runTest
import kotlinx.coroutines.test.setMain
import org.junit.After
import org.junit.Assert.assertEquals
import org.junit.Assert
import org.junit.Before
import org.junit.Test
import java.io.File
Expand Down Expand Up @@ -78,7 +78,7 @@ class InterestLocalDataSourceTest {
// when
val actual = interestLocalDataSource.getInterests().first()
// then
assertEquals(expected, actual)
Assert.assertEquals(expected, actual)
}

@Test
Expand All @@ -89,7 +89,7 @@ class InterestLocalDataSourceTest {
// when
val actual = interestLocalDataSource.getInterests().first()
// then
assertEquals(expected, actual)
Assert.assertEquals(expected, actual)
}


Expand All @@ -102,7 +102,7 @@ class InterestLocalDataSourceTest {
interestLocalDataSource.addInterest(interest)
val actual = interestLocalDataSource.getInterests().first()
// then
assertEquals(expected, actual)
Assert.assertEquals(expected, actual)
}

@Test
Expand All @@ -115,7 +115,7 @@ class InterestLocalDataSourceTest {
interestLocalDataSource.addInterest(interest)
val actual = interestLocalDataSource.getInterests().first()
// then
assertEquals(expected, actual)
Assert.assertEquals(expected, actual)
}

@Test
Expand All @@ -128,7 +128,7 @@ class InterestLocalDataSourceTest {
interestLocalDataSource.removeInterest(interest)
val actual = interestLocalDataSource.getInterests().first()
// then
assertEquals(expected, actual)
Assert.assertEquals(expected, actual)
}

@Test
Expand All @@ -141,7 +141,7 @@ class InterestLocalDataSourceTest {
interestLocalDataSource.removeInterest(interest)
val actual = interestLocalDataSource.getInterests().first()
// then
assertEquals(expected, actual)
Assert.assertEquals(expected, actual)
}

@Test
Expand All @@ -154,7 +154,7 @@ class InterestLocalDataSourceTest {
interestLocalDataSource.removeInterest(interest)
val actual = interestLocalDataSource.getInterests().first()
// then
assertEquals(expected, actual)
Assert.assertEquals(expected, actual)
}

@Test
Expand All @@ -171,7 +171,7 @@ class InterestLocalDataSourceTest {
interestLocalDataSource.removeInterest(interest3)
val actual = interestLocalDataSource.getInterests().first()
// then
assertEquals(expected, actual)
Assert.assertEquals(expected, actual)
}


Expand Down
Loading

0 comments on commit 7ae812f

Please sign in to comment.