Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ActionsManager#_determineCookieType #99

Merged
merged 1 commit into from Jan 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions config/settings/default.yml
Expand Up @@ -60,3 +60,4 @@ params:
metadata: 'metadata'
actions: 'actions'
cookie_policy: 'cp'
cookie_type: 'ct'
32 changes: 31 additions & 1 deletion spec/actions_manager_spec.coffee
Expand Up @@ -26,6 +26,10 @@ VALID_LINE_ITEM_DATA_2 = {
}
VALID_LINE_ITEM_DATA_2_STRINGIFIED = JSON.stringify(VALID_LINE_ITEM_DATA_2)

clear_all_cookies = ->
document.cookie.split(/;\s/g).forEach (cookie)->
document.cookie = "#{cookie.split('=')[0]}= ;expires=Thu, 01 Jan 1970 00:00:01 GMT"

api_session_promise_tests = ->
context 'when session retrieval fulfils', ->
beforeEach ->
Expand Down Expand Up @@ -68,7 +72,7 @@ action_reporting_tests = (reported_position) ->
p = @settings.params
expect(@payload).to.have.keys p.url, p.referrer,
p.shop_code, p.cookie_policy, p.metadata,
p.actions
p.actions, p.cookie_type

it 'has proper data in url key', ->
expect(@payload.url).to.equal @settings.url.current
Expand Down Expand Up @@ -106,6 +110,32 @@ action_reporting_tests = (reported_position) ->
type: @type
data: JSON.stringify(data)

describe 'cookie_type', ->
context 'when 1st party cookie exists', ->
beforeEach ->
# Clear all cookies
clear_all_cookies()

# Set basic 1st party cookie
document.cookie = "#{@settings.cookies.basic.session.name}=bar;"

@run()
@payload = @sendbeacon_spy.args[0][1]

it 'has proper data in cookie_type key', ->
expect(@payload.ct).to.equal '1'

context 'when 1st party cookie does not exist', ->
beforeEach ->
# Clear all cookies
clear_all_cookies()

@run()
@payload = @sendbeacon_spy.args[0][1]

it 'has proper data in cookie_type key', ->
expect(@payload.ct).to.equal '3'

describe 'ActionsManager', ->
before (done) ->
@analytics_session = 'analytics_session'
Expand Down
7 changes: 6 additions & 1 deletion src/actions_manager.coffee
Expand Up @@ -2,9 +2,10 @@ define [
'settings'
'reporter'
'runnable'
'biskoto'
'validator'
'analytics_url'
], (Settings, Reporter, Runnable, Validator, AnalyticsUrl) ->
], (Settings, Reporter, Runnable, Biskoto, Validator, AnalyticsUrl) ->
class ActionsManager
ActionsManager::[key] = method for key, method of Runnable

Expand Down Expand Up @@ -81,6 +82,7 @@ define [
payload[params.shop_code] = @session.shop_code
payload[params.metadata] = @_buildMetadata(JSON.parse(data))
payload[params.cookie_policy] = @session.cookie_policy
payload[params.cookie_type] = @_determineCookieType()
payload[params.actions] = [{
category: category
type: type
Expand Down Expand Up @@ -112,4 +114,7 @@ define [

meta

_determineCookieType: ->
if Biskoto.get(Settings.cookies.basic.session.name) then '1' else '3'

return ActionsManager
1 change: 1 addition & 0 deletions src/settings.coffee.sample
Expand Up @@ -38,6 +38,7 @@ define ->
metadata: '@@params.metadata'
actions: '@@params.actions'
cookie_policy: '@@params.cookie_policy'
cookie_type: '@@params.cookie_type'

###
Cookies
Expand Down