Skip to content

Commit 487a256

Browse files
gugalogithub-review-helper
authored and
github-review-helper
committed
Fix issue in acceptance tests
Acceptance tests started failing after this PR: #487 Because SDK configurations set up using deep-link where missing `companyName` property while the same property has been removed from the example app method that launched Widget SDK call/chat Activity because they have been deprecated.
1 parent 3945221 commit 487a256

File tree

1 file changed

+33
-54
lines changed

1 file changed

+33
-54
lines changed

app/src/main/java/com/glia/exampleapp/GliaWidgetsConfigManager.kt

Lines changed: 33 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -30,18 +30,23 @@ object GliaWidgetsConfigManager {
3030
saveVisitorContextAssetIdIfPresent(data, applicationContext)
3131
saveSiteIdToPrefs(data, applicationContext)
3232

33-
// We're not checking availability for every query param separately because this is for acceptance tests and we assume that link would be correct
34-
return if (SECRET_KEY == data.lastPathSegment) {
33+
// We're not checking availability for every query param separately because this is for acceptance tests and we assume that link would be correct
34+
if (SECRET_KEY == data.lastPathSegment) {
3535
saveSiteApiKeyAuthToPrefs(data, applicationContext)
36-
obtainConfigFromSecretDeepLink(data, applicationContext)
3736
} else {
3837
throw RuntimeException("deep link must start with \"glia://widgets/secret\"")
3938
}
39+
40+
// By this point all settings from deep link where saved to the shared prefs overriding the
41+
// defaults combining both together
42+
return createDefaultConfig(
43+
context = applicationContext,
44+
region = REGION_ACCEPTANCE
45+
)
4046
}
4147

4248
private fun saveVisitorContextAssetIdIfPresent(data: Uri, applicationContext: Context) {
43-
val visitorContextAssetId = data.getQueryParameter(VISITOR_CONTEXT_ASSET_ID_KEY)
44-
?: return
49+
val visitorContextAssetId = data.getQueryParameter(VISITOR_CONTEXT_ASSET_ID_KEY) ?: return
4550
val sharedPreferences = PreferenceManager.getDefaultSharedPreferences(applicationContext)
4651
sharedPreferences.edit().putString(
4752
applicationContext.getString(R.string.pref_context_asset_id),
@@ -53,14 +58,16 @@ object GliaWidgetsConfigManager {
5358
val queueId = data.getQueryParameter(QUEUE_ID_KEY) ?: return
5459
val sharedPreferences = PreferenceManager.getDefaultSharedPreferences(applicationContext)
5560
sharedPreferences.edit()
56-
.putString(applicationContext.getString(R.string.pref_queue_id), queueId).apply()
61+
.putString(applicationContext.getString(R.string.pref_queue_id), queueId)
62+
.apply()
5763
}
5864

5965
private fun saveSiteIdToPrefs(data: Uri, applicationContext: Context) {
6066
val siteId = data.getQueryParameter(SITE_ID_KEY) ?: return
6167
val sharedPreferences = PreferenceManager.getDefaultSharedPreferences(applicationContext)
6268
sharedPreferences.edit()
63-
.putString(applicationContext.getString(R.string.pref_site_id), siteId).apply()
69+
.putString(applicationContext.getString(R.string.pref_site_id), siteId)
70+
.apply()
6471
}
6572

6673
private fun saveSiteApiKeyAuthToPrefs(data: Uri, applicationContext: Context) {
@@ -74,60 +81,32 @@ object GliaWidgetsConfigManager {
7481
.apply()
7582
}
7683

77-
private fun obtainConfigFromSecretDeepLink(
78-
data: Uri,
79-
applicationContext: Context
80-
): GliaWidgetsConfig {
81-
return GliaWidgetsConfig.Builder()
82-
.setSiteApiKey(
83-
SiteApiKey(
84-
data.getQueryParameter(API_KEY_ID_KEY)!!, data.getQueryParameter(
85-
API_KEY_SECRET_KEY
86-
)!!
87-
)
88-
)
89-
.setSiteId(data.getQueryParameter(SITE_ID_KEY))
90-
.setRegion(REGION_ACCEPTANCE)
91-
.setContext(applicationContext)
92-
.build()
93-
}
94-
84+
@JvmStatic
9585
@JvmOverloads
9686
fun createDefaultConfig(
97-
applicationContext: Context,
98-
uiJsonRemoteConfig: String? = null
99-
): GliaWidgetsConfig {
100-
val sharedPreferences = PreferenceManager.getDefaultSharedPreferences(applicationContext)
101-
return configWithSiteApiKeyAuth(sharedPreferences, applicationContext, uiJsonRemoteConfig)
102-
}
103-
104-
private fun configWithSiteApiKeyAuth(
105-
preferences: SharedPreferences,
106-
applicationContext: Context,
107-
uiJsonRemoteConfig: String?
87+
context: Context,
88+
preferences: SharedPreferences = PreferenceManager.getDefaultSharedPreferences(context),
89+
uiJsonRemoteConfig: String? = null,
90+
region: String = REGION_BETA
10891
): GliaWidgetsConfig {
10992
val apiKeyId = preferences.getString(
110-
applicationContext.getString(R.string.pref_api_key_id),
111-
applicationContext.getString(R.string.glia_api_key_id)
93+
context.getString(R.string.pref_api_key_id),
94+
context.getString(R.string.glia_api_key_id)
11295
)
11396
val apiKeySecret = preferences.getString(
114-
applicationContext.getString(R.string.pref_api_key_secret),
115-
applicationContext.getString(R.string.glia_api_key_secret)
97+
context.getString(R.string.pref_api_key_secret),
98+
context.getString(R.string.glia_api_key_secret)
11699
)
117100
val siteId = preferences.getString(
118-
applicationContext.getString(R.string.pref_site_id),
119-
applicationContext.getString(R.string.site_id)
101+
context.getString(R.string.pref_site_id),
102+
context.getString(R.string.site_id)
120103
)
121-
val companyName =
122-
preferences.getString(applicationContext.getString(R.string.pref_company_name), "")
123-
val useOverlay =
124-
preferences.getBoolean(applicationContext.getString(R.string.pref_use_overlay), true)
125-
val bounded = applicationContext.getString(R.string.screen_sharing_mode_app_bounded)
126-
val unbounded = applicationContext.getString(R.string.screen_sharing_mode_unbounded)
127-
val screenSharingMode: ScreenSharing.Mode
128-
screenSharingMode = if (preferences.getString(
129-
applicationContext.getString(R.string.pref_screen_sharing_mode),
130-
unbounded
104+
val companyName = preferences.getString(context.getString(R.string.pref_company_name), "")
105+
val useOverlay = preferences.getBoolean(context.getString(R.string.pref_use_overlay), true)
106+
val bounded = context.getString(R.string.screen_sharing_mode_app_bounded)
107+
val unbounded = context.getString(R.string.screen_sharing_mode_unbounded)
108+
val screenSharingMode = if (preferences.getString(
109+
context.getString(R.string.pref_screen_sharing_mode), unbounded
131110
) == bounded
132111
) {
133112
ScreenSharing.Mode.APP_BOUNDED
@@ -137,11 +116,11 @@ object GliaWidgetsConfigManager {
137116
return GliaWidgetsConfig.Builder()
138117
.setSiteApiKey(SiteApiKey(apiKeyId!!, apiKeySecret!!))
139118
.setSiteId(siteId)
140-
.setRegion(REGION_BETA)
119+
.setRegion(region)
141120
.setCompanyName(companyName)
142121
.setUseOverlay(useOverlay)
143122
.setScreenSharingMode(screenSharingMode)
144-
.setContext(applicationContext)
123+
.setContext(context)
145124
.setUiJsonRemoteConfig(uiJsonRemoteConfig)
146125
.build()
147126
}

0 commit comments

Comments
 (0)