Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/add_cookie_type_to_actions_manager'
Browse files Browse the repository at this point in the history
Merges #99
  • Loading branch information
MrGoumX committed Jan 12, 2024
2 parents a9a4d7e + 3b4e5e0 commit b4bbca5
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 2 deletions.
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

0 comments on commit b4bbca5

Please sign in to comment.