-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[cleanup] feat: Delete user cleanup api
- Loading branch information
1 parent
f960cc5
commit 90caef3
Showing
9 changed files
with
113 additions
and
9 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
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,31 @@ | ||
import { request, expect, APIResponse } from '@playwright/test'; | ||
import getApiUrl from './getApiUrl'; | ||
|
||
const apiLogin = async (options: { | ||
username: string; | ||
password: string; | ||
}): Promise<APIResponse> => { | ||
if (!options.username || !options.password) { | ||
throw new Error('Username and Password is required to login'); | ||
} | ||
|
||
const context = await request.newContext({ | ||
baseURL: await getApiUrl(), | ||
}); | ||
|
||
const loginResponse = await context.post('/api/login', { | ||
headers: { | ||
'Content-Type': 'application/json', | ||
}, | ||
data: { | ||
username: options.username, | ||
password: options.password, | ||
}, | ||
}); | ||
|
||
expect(loginResponse.ok()).toBeTruthy(); | ||
expect(loginResponse.status()).toBe(200); | ||
return loginResponse; | ||
}; | ||
|
||
export default apiLogin; |
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 { request, expect, APIResponse } from '@playwright/test'; | ||
import getApiUrl from './getApiUrl'; | ||
|
||
const deleteUser = async (token: string | null): Promise<APIResponse> => { | ||
if (!token) { | ||
throw new Error('Token is required to delete user'); | ||
} | ||
|
||
const context = await request.newContext({ | ||
baseURL: await getApiUrl(), | ||
}); | ||
|
||
const deleteResponse = await context.delete('/api/users', { | ||
headers: { | ||
Authorization: `Bearer ${token}`, | ||
'Content-Type': 'application/json', | ||
}, | ||
}); | ||
|
||
expect(deleteResponse.ok()).toBeTruthy(); | ||
expect(deleteResponse.status()).toBe(204); | ||
|
||
return deleteResponse; | ||
}; | ||
|
||
export default deleteUser; |
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,17 @@ | ||
import playwrightConfig from '../playwright.config'; | ||
|
||
const getApiUrl = async () => { | ||
const baseURL = playwrightConfig.use?.baseURL; | ||
|
||
const apiURL = baseURL?.includes('localhost') | ||
? 'http://localhost:5000' | ||
: 'https://notes-app-full-stack-be.onrender.com'; | ||
|
||
if (!baseURL) { | ||
throw new Error('Base URL is required to make API requests'); | ||
} | ||
|
||
return apiURL; | ||
}; | ||
|
||
export default getApiUrl; |
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
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