-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: Update snapshot test to cleanup test resources after each test …
…run (#391) ## Changes - N/A ticket: [AC-4343] ## Additional Notes - Updated snapshot test to cleanup test resources after each test run - You can check test resources being created and then deleted in real time during test run - [Run test locally](https://sendbird.atlassian.net/wiki/spaces/AC/pages/2610724994/Widget+snapshot+test+plan) ## Checklist Before requesting a code review, please check the following: - [x] **[Required]** CI has passed all checks. - [x] **[Required]** A self-review has been conducted to ensure there are no minor mistakes. - [x] **[Required]** Unnecessary comments/debugging code have been removed. - [x] **[Required]** All requirements specified in the ticket have been accurately implemented. - [ ] Ensure the ticket has been updated with the sprint, status, and story points. [AC-4343]: https://sendbird.atlassian.net/browse/AC-4343?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ --------- Co-authored-by: Hyungu Kang | Airen <[email protected]>
- Loading branch information
Showing
5 changed files
with
109 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { Page } from '@playwright/test'; | ||
|
||
export const getKey = (appId: string, botId: string) => { | ||
return `@sendbird/chat-ai-widget/${appId}/${botId}`; | ||
}; | ||
|
||
export type WidgetSessionCache = { | ||
userId: string; | ||
channelUrl: string; | ||
}; | ||
|
||
export async function getWidgetSessionCache( | ||
page: Page, | ||
{ appId, botId }: { appId: string; botId: string }, | ||
): Promise<WidgetSessionCache | null> { | ||
const value = await page.evaluate(({ key }) => localStorage.getItem(key), { key: getKey(appId, botId) }); | ||
if (value) { | ||
try { | ||
return JSON.parse(value); | ||
} catch { | ||
return null; | ||
} | ||
} else { | ||
return null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { ApiHost, ApiToken } from '../const'; | ||
|
||
interface RequestParams { | ||
url: string; | ||
headers?: object; | ||
data?: object; | ||
} | ||
|
||
function createQueryString(params: any): string { | ||
const items: string[] = []; | ||
for (const key in params) { | ||
items.push(`${key}=${encodeURIComponent(params[key])}`); | ||
} | ||
return items.join('&'); | ||
} | ||
|
||
function createHeaders(): object { | ||
return { | ||
'Api-Token': ApiToken, | ||
'Content-Type': 'application/json', | ||
}; | ||
} | ||
|
||
async function requestDelete(requestParams: RequestParams) { | ||
const response = await fetch(`${ApiHost}${requestParams.url}?${createQueryString(requestParams.data)}`, { | ||
method: 'DELETE', | ||
headers: createHeaders() as Headers, | ||
body: JSON.stringify(requestParams.data) || null, | ||
}); | ||
return await response.json(); | ||
} | ||
|
||
export async function deleteChannel(channelUrl: string): Promise<object[]> { | ||
return await requestDelete({ | ||
url: `/v3/group_channels/${encodeURIComponent(channelUrl)}`, | ||
}); | ||
} | ||
|
||
export async function deleteUser(userId: string): Promise<object[]> { | ||
return await requestDelete({ | ||
url: `/v3/users/${encodeURIComponent(userId)}`, | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters