LibreChat/e2e/specs/settings.spec.ts
Danny Avila 33f087d38f
feat: Refresh Token for improved Session Security (#927)
* feat(api): refresh token logic

* feat(client): refresh token logic

* feat(data-provider): refresh token logic

* fix: SSE uses esm

* chore: add default refresh token expiry to AuthService, add message about env var not set when generating a token

* chore: update scripts to more compatible bun methods, ran bun install again

* chore: update env.example and playwright workflow with JWT_REFRESH_SECRET

* chore: update breaking changes docs

* chore: add timeout to url visit

* chore: add default SESSION_EXPIRY in generateToken logic, add act script for testing github actions

* fix(e2e): refresh automatically in development environment to pass e2e tests
2023-09-11 13:10:46 -04:00

75 lines
2.6 KiB
TypeScript

import { expect, test } from '@playwright/test';
test.describe('Settings suite', () => {
test('Last Bing settings', async ({ page }) => {
await page.goto('http://localhost:3080/', { timeout: 5000 });
await page.evaluate(() =>
window.localStorage.setItem(
'lastConversationSetup',
JSON.stringify({
conversationId: 'new',
title: 'New Chat',
endpoint: 'bingAI',
createdAt: '',
updatedAt: '',
jailbreak: false,
context: null,
systemMessage: null,
toneStyle: 'creative',
jailbreakConversationId: null,
conversationSignature: null,
clientId: null,
invocationId: 1,
}),
),
);
await page.goto('http://localhost:3080/', { timeout: 5000 });
const initialLocalStorage = await page.evaluate(() => window.localStorage);
const lastConvoSetup = JSON.parse(initialLocalStorage.lastConversationSetup);
expect(lastConvoSetup.endpoint).toEqual('bingAI');
const newTopicButton = page.getByTestId('new-conversation-menu');
await newTopicButton.click();
// includes the icon + endpoint names in obj property
const endpointItem = page.getByTestId('endpoint-item-bingAI');
await endpointItem.click();
await page.getByTestId('text-input').click();
const button1 = page.getByRole('button', { name: 'Mode: BingAI' });
const button2 = page.getByRole('button', { name: 'Mode: Sydney' });
try {
await button1.click({ timeout: 100 });
} catch (e) {
// console.log('Bing button', e);
}
try {
await button2.click({ timeout: 100 });
} catch (e) {
// console.log('Sydney button', e);
}
await page.getByRole('option', { name: 'Sydney' }).click();
await page.getByRole('tab', { name: 'Balanced' }).click();
// Change Endpoint to see if settings will persist
await newTopicButton.click();
await page.getByRole('menuitemradio', { name: 'ChatGPT OpenAI' }).click();
// Close endpoint menu & re-select BingAI
await page.getByTestId('text-input').click();
await newTopicButton.click();
await endpointItem.click();
// Check if the settings persisted
const localStorage = await page.evaluate(() => window.localStorage);
const lastBingSettings = JSON.parse(localStorage.lastBingSettings);
const { jailbreak, toneStyle } = lastBingSettings;
expect(jailbreak).toBeTruthy();
expect(toneStyle).toEqual('balanced');
const button = page.getByRole('button', { name: 'Mode: Sydney' });
expect(button.count()).toBeTruthy();
});
});