Skip to content

Commit 8e27704

Browse files
committed
Simplify cookies and add extra unit tests
1 parent ca3a0fe commit 8e27704

File tree

3 files changed

+13
-31
lines changed

3 files changed

+13
-31
lines changed

rb/lib/selenium/webdriver/bidi/network/cookies.rb

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -21,34 +21,16 @@ module Selenium
2121
module WebDriver
2222
class BiDi
2323
class Cookies < Hash
24-
KNOWN_KEYS = %i[name value domain path expiry http_only secure same_site size max_age].freeze
25-
2624
def initialize(cookies = {})
2725
super()
2826
merge!(cookies)
2927
end
3028

3129
def as_json
32-
cookie_hash = {
33-
name: self[:name].to_s,
34-
value: {
35-
type: 'string',
36-
value: self[:value].to_s
37-
},
38-
domain: self[:domain],
39-
path: self[:path],
40-
size: self[:size],
41-
httpOnly: self[:http_only],
42-
secure: self[:secure],
43-
sameSite: self[:same_site],
44-
expiry: self[:expiry],
45-
maxAge: self[:max_age]
46-
}
47-
48-
extra_fields = except(KNOWN_KEYS)
49-
cookie_hash.merge!(extra_fields) { |_k, old_val, _new_val| old_val }
30+
self[:name] = self[:name].to_s
31+
self[:value] = {type: 'string', value: self[:value].to_s}
5032

51-
[cookie_hash.compact]
33+
[compact]
5234
end
5335
end
5436
end # BiDi

rb/spec/integration/selenium/webdriver/network_spec.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -155,9 +155,9 @@ module WebDriver
155155
domain: 'example.com',
156156
path: '/path',
157157
size: 1234,
158-
http_only: true,
158+
httpOnly: true,
159159
secure: true,
160-
same_site: 'Strict',
160+
sameSite: 'Strict',
161161
expiry: 1234
162162
})
163163
request.body = ({test: 'example'})
@@ -247,11 +247,11 @@ module WebDriver
247247
response.cookies({
248248
name: 'foo',
249249
domain: 'localhost',
250-
http_only: true,
250+
httpOnly: true,
251251
expiry: '1_000_000',
252-
max_age: 1_000,
252+
maxAge: 1_000,
253253
path: '/',
254-
same_site: 'none',
254+
sameSite: 'none',
255255
secure: false
256256
})
257257
response.continue

rb/spec/unit/selenium/webdriver/bidi/cookies_spec.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@ class BiDi
4444
domain: 'example.com',
4545
path: '/path',
4646
size: 1234,
47-
http_only: true,
47+
httpOnly: true,
4848
secure: true,
49-
same_site: 'Strict',
49+
sameSite: 'Strict',
5050
expiry: 1234
5151
}
5252
)
@@ -73,11 +73,11 @@ class BiDi
7373
name: 'test',
7474
value: 'bar',
7575
domain: 'localhost',
76-
http_only: true,
76+
httpOnly: true,
7777
expiry: '1_000_000',
78-
max_age: 1_000,
78+
maxAge: 1_000,
7979
path: '/',
80-
same_site: 'lax',
80+
sameSite: 'lax',
8181
secure: false
8282
})
8383

0 commit comments

Comments
 (0)