mirror of
https://github.com/usebruno/bruno.git
synced 2026-07-07 14:08:38 +00:00
* feat(cookies): add direct cookie access methods and update translations
- Introduced new methods for direct cookie access: `bru.cookies.get`, `bru.cookies.has`, and `bru.cookies.toObject`.
- Updated translation mappings in `bruno-to-postman-translator` and `postman-to-bruno-translator` to support these new methods.
- Enhanced tests to verify correct translation between `bru` and `pm` cookie methods, including mixed usage scenarios.
- Updated `Bru` class to handle cookie access based on the current request URL.
* feat(cookies): enhance cookie management with new methods and refactor
- Added new cookie methods: `toString`, `clear`, `delete`, `one`, `all`, `idx`, `count`, `indexOf`, `find`, `filter`, `each`, `map`, and `reduce` to `bru.cookies`.
- Refactored `Bru` class to utilize a new `CookieList` for cookie management, improving structure and readability.
- Updated translation mappings in `bruno-to-postman-translator` and `postman-to-bruno-translator` to include new cookie methods.
- Introduced `PropertyList` and `ReadOnlyPropertyList` classes for better data structure management.
- Enhanced tests for comprehensive coverage of new cookie functionalities and their interactions.
* docs(readonly-property-list): clarify array usage in constructor comments
* feat(cookies): add direct cookie manipulation tests and methods
* feat(cookies): add hasCookie method for checking cookie existence
* fix
* refactor(cookies): simplify cookie method translations
* feat(cookies): expand cookie API with new methods and tests
- Added new cookie methods: `get`, `has`, `toString`, `clear`, `upsert`, `remove`, `idx`, and `indexOf` to enhance cookie management.
- Updated translation mappings for `bru.cookies` to include new methods in `bruno-to-postman-translator` and `postman-to-bruno-translator`.
- Introduced tests for new methods and their interactions, ensuring comprehensive coverage of cookie functionalities.
- Enhanced existing tests to validate correct behavior of cookie methods across different scenarios.
* refactor(cookies): update CookieList to extend PropertyList and improve error handling
* test(cookies): add regression tests for jar and direct cookie patterns
- Introduced regression tests to ensure that jar patterns are correctly prioritized over direct cookie access patterns in translations.
- Updated `CookieList` to extend `ReadOnlyPropertyList` instead of `PropertyList`, clarifying its functionality.
- Refactored cookie method handling in the `bru` shim to utilize a new asynchronous bridge for improved error handling and consistency.
* refactor(cookies): update translations and remove PropertyList
- Enhanced comments in `postman-translations.js` to clarify the order of cookie jar translations.
- Updated `cookie-list.js` comments to better describe the factory function for the cookie jar.
- Removed the `PropertyList` class and its associated tests, streamlining the codebase and focusing on `ReadOnlyPropertyList` and `CookieList` for cookie management.
* fix(cookies): normalize tough-cookie objects and improve remove method comments
- Updated `CookieList` to normalize tough-cookie instances to plain objects, preventing circular references and exposing internal structures.
- Enhanced comments in the `remove` method to clarify behavior when removing non-existent or empty-named cookies.
* test(cookies): update tests to use async/await for consistency
* test(cookies): use async/await in cookie tests for consistency
* refactor(readonly-property-list): update get and reduce methods for improved behavior
* fix(cookies): update cookie method signature in autocomplete hints and enhance translation comments
- Modified the autocomplete hint for `bru.cookies.has` to include the new signature with an optional value parameter.
- Improved comments in `postman-translations.js` to clarify the order of cookie jar translation patterns for better understanding.
* refactor(cookies): introduce PropertyList for enhanced cookie management
* refactor(property-list): simplify repopulate method and enhance item handling logic
* feat(cookies): implement PropertyList bridge for enhanced cookie management
- Introduced a new `createPropertyListBridge` utility to streamline the integration of cookie methods into the QuickJS VM.
- Replaced the previous async cookie bridge with a more flexible approach, allowing for both synchronous and asynchronous cookie operations.
- Added comprehensive tests to validate the functionality of the new cookie methods in both developer and safe modes.
- Updated existing cookie tests to ensure compatibility with the new PropertyList structure.
* fix(tests): correct expected passed requests in cookie tests
- Updated the expected number of passed requests in the cookie tests from 34 to 6 to reflect the correct validation results.
- Ensured consistency in test assertions across multiple test cases for the PropertyList API.
* fix(cookies): update cookie URLs to use localhost for testing
- Changed all cookie-related test scripts to use `{{localhost}}` instead of `{{host}}` for the ping URL, ensuring consistency in local testing environments.
- Updated the cookie test suite to reflect the new URL structure, enhancing the reliability of the tests.
- Removed outdated cookie test files to streamline the test suite.
* refactor(cookies): standardize cookie handling with localhost variable
- Updated cookie test scripts to utilize the `{{localhost}}` variable for setting and retrieving cookies, ensuring consistency across tests.
- Enhanced clarity in comments regarding cookie behavior for different domains.
- Improved test assertions to validate cookie management functionality more effectively.
* refactor(property-list, readonly-property-list): update methods to use private class fields
* feat(cookies): enhance CookieList API with detailed documentation and method improvements
- Updated the `CookieList` class to provide comprehensive documentation on cookie management methods, including `add`, `upsert`, `remove`, and `delete`.
- Improved method signatures to support both callback and Promise-based usage for asynchronous operations.
- Added detailed descriptions for read and write methods, including examples and expected behavior.
- Enhanced the integration of the `CookieList` with the QuickJS VM by updating the property list bridge to include `toJSON` in sync read object methods.
* feat(cookies): add detailed examples and improve async bridge documentation
- Enhanced the `createPropertyListBridge` function documentation with comprehensive examples for setting up cookie methods in QuickJS.
- Clarified the two-phase setup process for async write methods, detailing the registration of bridge functions and the generation of JavaScript code for method wrappers.
- Added a new test case for the `toJSON()` method to ensure it returns a cloned array of all cookies, validating the expected structure and properties.
* fix(assert-runtime): correct syntax error in response parser assignment
- Added a semicolon at the end of the response parser assignment to ensure proper syntax in the AssertRuntime class.
238 lines
7.3 KiB
JavaScript
238 lines
7.3 KiB
JavaScript
const PropertyList = require('../src/property-list');
|
|
const ReadOnlyPropertyList = require('../src/readonly-property-list');
|
|
|
|
describe('PropertyList', () => {
|
|
// ── Inheritance ───────────────────────────────────────────────────────
|
|
|
|
test('instanceof ReadOnlyPropertyList', () => {
|
|
const list = new PropertyList({ items: [] });
|
|
expect(list).toBeInstanceOf(ReadOnlyPropertyList);
|
|
expect(list).toBeInstanceOf(PropertyList);
|
|
});
|
|
|
|
test('isPropertyList() returns true', () => {
|
|
const list = new PropertyList({ items: [] });
|
|
expect(ReadOnlyPropertyList.isPropertyList(list)).toBe(true);
|
|
});
|
|
|
|
// ── Static Mode Mutations ─────────────────────────────────────────────
|
|
|
|
describe('static mode', () => {
|
|
let list;
|
|
|
|
beforeEach(() => {
|
|
list = new PropertyList({
|
|
items: [
|
|
{ key: 'a', value: '1' },
|
|
{ key: 'b', value: '2' },
|
|
{ key: 'c', value: '3' }
|
|
]
|
|
});
|
|
});
|
|
|
|
// ── add / append ──
|
|
|
|
test('add() appends item to end', () => {
|
|
list.add({ key: 'd', value: '4' });
|
|
expect(list.count()).toBe(4);
|
|
expect(list.idx(3)).toEqual({ key: 'd', value: '4' });
|
|
});
|
|
|
|
test('append() is alias for add()', () => {
|
|
list.append({ key: 'd', value: '4' });
|
|
expect(list.count()).toBe(4);
|
|
expect(list.idx(3)).toEqual({ key: 'd', value: '4' });
|
|
});
|
|
|
|
// ── prepend ──
|
|
|
|
test('prepend() inserts item at beginning', () => {
|
|
list.prepend({ key: 'z', value: '0' });
|
|
expect(list.count()).toBe(4);
|
|
expect(list.idx(0)).toEqual({ key: 'z', value: '0' });
|
|
expect(list.idx(1)).toEqual({ key: 'a', value: '1' });
|
|
});
|
|
|
|
// ── insert ──
|
|
|
|
test('insert() before key string', () => {
|
|
list.insert({ key: 'x', value: '9' }, 'b');
|
|
expect(list.count()).toBe(4);
|
|
expect(list.idx(1)).toEqual({ key: 'x', value: '9' });
|
|
expect(list.idx(2)).toEqual({ key: 'b', value: '2' });
|
|
});
|
|
|
|
test('insert() before item object', () => {
|
|
list.insert({ key: 'x', value: '9' }, { key: 'c', value: '3' });
|
|
expect(list.count()).toBe(4);
|
|
expect(list.idx(2)).toEqual({ key: 'x', value: '9' });
|
|
expect(list.idx(3)).toEqual({ key: 'c', value: '3' });
|
|
});
|
|
|
|
test('insert() appends when reference not found', () => {
|
|
list.insert({ key: 'x', value: '9' }, 'missing');
|
|
expect(list.count()).toBe(4);
|
|
expect(list.idx(3)).toEqual({ key: 'x', value: '9' });
|
|
});
|
|
|
|
// ── insertAfter ──
|
|
|
|
test('insertAfter() after key string', () => {
|
|
list.insertAfter({ key: 'x', value: '9' }, 'a');
|
|
expect(list.count()).toBe(4);
|
|
expect(list.idx(0)).toEqual({ key: 'a', value: '1' });
|
|
expect(list.idx(1)).toEqual({ key: 'x', value: '9' });
|
|
expect(list.idx(2)).toEqual({ key: 'b', value: '2' });
|
|
});
|
|
|
|
test('insertAfter() after item object', () => {
|
|
list.insertAfter({ key: 'x', value: '9' }, { key: 'b', value: '2' });
|
|
expect(list.count()).toBe(4);
|
|
expect(list.idx(1)).toEqual({ key: 'b', value: '2' });
|
|
expect(list.idx(2)).toEqual({ key: 'x', value: '9' });
|
|
});
|
|
|
|
test('insertAfter() appends when reference not found', () => {
|
|
list.insertAfter({ key: 'x', value: '9' }, 'missing');
|
|
expect(list.count()).toBe(4);
|
|
expect(list.idx(3)).toEqual({ key: 'x', value: '9' });
|
|
});
|
|
|
|
// ── remove ──
|
|
|
|
test('remove() by predicate', () => {
|
|
list.remove((item) => item.value === '2');
|
|
expect(list.count()).toBe(2);
|
|
expect(list.has('b')).toBe(false);
|
|
});
|
|
|
|
test('remove() by key string', () => {
|
|
list.remove('a');
|
|
expect(list.count()).toBe(2);
|
|
expect(list.has('a')).toBe(false);
|
|
});
|
|
|
|
test('remove() by item object', () => {
|
|
list.remove({ key: 'c', value: '3' });
|
|
expect(list.count()).toBe(2);
|
|
expect(list.has('c')).toBe(false);
|
|
});
|
|
|
|
test('remove() by item object that does not exist is no-op', () => {
|
|
list.remove({ key: 'missing', value: '0' });
|
|
expect(list.count()).toBe(3);
|
|
});
|
|
|
|
// ── clear ──
|
|
|
|
test('clear() empties the list', () => {
|
|
list.clear();
|
|
expect(list.count()).toBe(0);
|
|
expect(list.all()).toEqual([]);
|
|
});
|
|
|
|
// ── upsert ──
|
|
|
|
test('upsert() updates existing item by key', () => {
|
|
list.upsert({ key: 'b', value: 'updated' });
|
|
expect(list.count()).toBe(3);
|
|
expect(list.get('b')).toBe('updated');
|
|
});
|
|
|
|
test('upsert() appends new item when key not found', () => {
|
|
list.upsert({ key: 'd', value: '4' });
|
|
expect(list.count()).toBe(4);
|
|
expect(list.get('d')).toBe('4');
|
|
});
|
|
|
|
// ── populate ──
|
|
|
|
test('populate() replaces all items', () => {
|
|
list.populate([{ key: 'x', value: '10' }]);
|
|
expect(list.count()).toBe(1);
|
|
expect(list.get('x')).toBe('10');
|
|
});
|
|
|
|
test('populate() with non-array sets empty list', () => {
|
|
list.populate(null);
|
|
expect(list.count()).toBe(0);
|
|
});
|
|
|
|
// ── repopulate ──
|
|
|
|
test('repopulate() clears and replaces', () => {
|
|
list.repopulate([{ key: 'y', value: '20' }]);
|
|
expect(list.count()).toBe(1);
|
|
expect(list.get('y')).toBe('20');
|
|
});
|
|
|
|
test('repopulate() with non-array sets empty list', () => {
|
|
list.repopulate(undefined);
|
|
expect(list.count()).toBe(0);
|
|
});
|
|
|
|
// ── assimilate ──
|
|
|
|
test('assimilate() merges from array', () => {
|
|
list.assimilate([{ key: 'd', value: '4' }]);
|
|
expect(list.count()).toBe(4);
|
|
expect(list.get('d')).toBe('4');
|
|
});
|
|
|
|
test('assimilate() merges from PropertyList', () => {
|
|
const source = new PropertyList({
|
|
items: [{ key: 'd', value: '4' }]
|
|
});
|
|
list.assimilate(source);
|
|
expect(list.count()).toBe(4);
|
|
expect(list.get('d')).toBe('4');
|
|
});
|
|
|
|
test('assimilate() with prune clears first', () => {
|
|
list.assimilate([{ key: 'x', value: '10' }], true);
|
|
expect(list.count()).toBe(1);
|
|
expect(list.get('x')).toBe('10');
|
|
});
|
|
|
|
test('assimilate() with invalid source is no-op', () => {
|
|
list.assimilate('not-a-list');
|
|
expect(list.count()).toBe(3);
|
|
});
|
|
});
|
|
|
|
// ── Dynamic Mode ──────────────────────────────────────────────────────
|
|
|
|
describe('dynamic mode', () => {
|
|
let list;
|
|
|
|
beforeEach(() => {
|
|
list = new PropertyList({
|
|
dataSource: () => [{ key: 'x', value: '10' }]
|
|
});
|
|
});
|
|
|
|
test.each([
|
|
['add', 'add'],
|
|
['append', 'add'],
|
|
['prepend', 'prepend'],
|
|
['insert', 'insert'],
|
|
['insertAfter', 'insertAfter'],
|
|
['remove', 'remove'],
|
|
['clear', 'clear'],
|
|
['upsert', 'upsert'],
|
|
['populate', 'populate'],
|
|
['repopulate', 'repopulate'],
|
|
['assimilate', 'assimilate']
|
|
])('%s() throws in dynamic mode', (method, errorMethod) => {
|
|
expect(() => list[method]({ key: 'a', value: '1' })).toThrow(
|
|
`${errorMethod}() is not supported in dynamic mode. Override in subclass.`
|
|
);
|
|
});
|
|
|
|
test('read methods still work', () => {
|
|
expect(list.get('x')).toBe('10');
|
|
expect(list.count()).toBe(1);
|
|
});
|
|
});
|
|
});
|