Files
bruno/packages/bruno-tests/collection/scripting/api/bru/cookies/hasCookie.bru
sanish chirayath d30ab4d984 feat: add translations for direct cookie access methods (#7070)
* feat: add translations for direct cookie access methods

- Implement translations for pm.cookies.has, pm.cookies.get, and pm.cookies.toObject to their corresponding bru.cookies methods.
- Enhance the postman-to-bruno translator to handle these new cookie access patterns.
- Add unit tests to verify the correct conversion of cookie access methods in various scenarios.

* refactor: simplify optional member expression handling in postman-to-bruno translator

- Streamlined the code for handling optional member expressions in the translation of cookie access methods.
- Updated unit test to verify the correct output format for pm.cookies.toObject() conversion.

* refactor: enhance handling of await expressions in cookie translations

- Updated the postman-to-bruno translator to wrap await expressions in parentheses for improved clarity and consistency.
- Adjusted unit tests to reflect the new output format for cookie access methods, ensuring accurate translation of pm.cookies.get calls.

* refactor: update cookie access translations to use hasCookie method

- Modified translations for pm.cookies.has to utilize the new bru.cookies.hasCookie method for improved clarity and functionality.
- Updated related unit tests to reflect changes in expected output for cookie existence checks.
- Added new tests to validate the behavior of the hasCookie method in various scenarios.
2026-02-12 14:30:35 +05:30

45 lines
1022 B
Plaintext

meta {
name: hasCookie
type: http
seq: 10
}
get {
url: {{host}}/ping
body: none
auth: inherit
}
script:pre-request {
const jar = bru.cookies.jar()
jar.setCookie("https://testbench-sanity.usebruno.com", "existing_cookie", "some_value")
}
tests {
const jar = bru.cookies.jar()
test("should return true for a cookie that exists", async function() {
const exists = await jar.hasCookie('https://testbench-sanity.usebruno.com', 'existing_cookie');
expect(exists).to.be.true;
});
test("should return false for a cookie that does not exist", async function() {
const exists = await jar.hasCookie('https://testbench-sanity.usebruno.com', 'nonexistent_cookie');
expect(exists).to.be.false;
});
jar.hasCookie("https://testbench-sanity.usebruno.com", "existing_cookie", function(error, exists) {
test("should work with callback pattern", function() {
expect(error).to.be.null;
expect(exists).to.be.true;
});
});
jar.clear()
}
settings {
encodeUrl: true
}