Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TestGru] Add unit test for app/routes/api.chat.ts #11

Closed
wants to merge 2 commits into from
Closed
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
47 changes: 47 additions & 0 deletions app/routes/api.chat.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { describe, it, expect } from 'vitest';
import { parseCookies } from './api.chat';

describe('parseCookies', () => {
it('should parse valid cookie string', () => {
const cookieStr = 'name=value; key=123; foo=bar';
const result = parseCookies(cookieStr);
expect(result).toEqual({
name: 'value',
key: '123',
foo: 'bar',
});
});

it('should handle empty cookie string', () => {
const result = parseCookies('');
expect(result).toEqual({});
});

it('should handle malformed cookie string', () => {
const cookieStr = 'invalid;cookie=value;;=empty;novalue=';
const result = parseCookies(cookieStr);
expect(result).toEqual({
invalid: '',
cookie: 'value',
novalue: '',
});
});

it('should handle cookies with special characters', () => {
const cookieStr = 'name=%20value%20; key=%3D%3D; foo=bar%20baz';
const result = parseCookies(cookieStr);
expect(result).toEqual({
name: ' value ',
key: '==',
foo: 'bar baz',
});
});

it('should handle cookies with equals sign in value', () => {
const cookieStr = 'key=value=with=equals';
const result = parseCookies(cookieStr);
expect(result).toEqual({
key: 'value=with=equals',
});
});
});
3 changes: 3 additions & 0 deletions app/routes/api.chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -286,3 +286,6 @@ async function chatAction({ context, request }: ActionFunctionArgs) {
});
}
}


export { logger, parseCookies };
Loading