Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -200,4 +200,30 @@ describe('test CookieJar', () => {
cookieList.upsert(upsertedC1);
expect(cookieList.one('c1')).toEqual(upsertedC1.valueOf());
});

it('toObject returns {} when there are no cookies', () => {
expect(new CookieList([]).toObject()).toEqual({});
expect(new CookieObject(null).toObject()).toEqual({});
});

it('toObject returns a key-value map when there are cookies', () => {
const cookieList = new CookieList([new Cookie({ key: 'c1', value: 'v1' }), new Cookie({ key: 'c2', value: 'v2' })]);
expect(cookieList.toObject()).toEqual({ c1: 'v1', c2: 'v2' });

const cookieObject = new CookieObject({
_id: '',
type: 'CookieJar',
parentId: '',
modified: 0,
created: 0,
isPrivate: false,
name: 'my jar',
cookies: [
{ id: '1', key: 'c1', value: 'v1', domain: 'inso.com' },
{ id: '2', key: 'c2', value: 'v2', domain: 'inso.com' },
],
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} as any);
Comment on lines +213 to +226
expect(cookieObject.toObject()).toEqual({ c1: 'v1', c2: 'v2' });
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,14 @@ export class CookieList extends PropertyList<Cookie> {
static isCookieList(obj: object) {
return '_kind' in obj && obj._kind === 'CookieList';
}

override toObject(_excludeDisabled?: boolean, _caseSensitive?: boolean, _multiValue?: boolean, _sanitizeKeys?: boolean) {
const obj: Record<string, string> = {};
this.list.forEach(cookie => {
obj[cookie.key] = cookie.valueOf();
});
return obj;
}
Comment on lines +191 to +197
}

export class CookieObject extends CookieList {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,12 @@ export class PropertyList<T extends Property> {

// TODO: unsupported yet

toObject(_excludeDisabled?: boolean, _caseSensitive?: boolean, _multiValue?: boolean, _sanitizeKeys?: boolean) {
toObject(
_excludeDisabled?: boolean,
_caseSensitive?: boolean,
_multiValue?: boolean,
_sanitizeKeys?: boolean,
): Record<string, any> | Record<string, any>[] {
// it just dump all properties of each element without arguments
// then user is able to handle them by themself
return this.list.map(elem => elem.toJSON());
Expand Down
Loading