-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathdelete-api.spec.js
More file actions
48 lines (38 loc) · 1.71 KB
/
delete-api.spec.js
File metadata and controls
48 lines (38 loc) · 1.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// @ts-check
import { expect, test } from '@playwright/test';
// Base API URL - adjust this to match your actual API endpoint
const API_BASE_URL = process.env.API_BASE_URL || 'https://dummyjson.com';
const USERS_ENDPOINT = '/users';
test.describe('DELETE User API', () => {
test('Remove user 1 ',{tag: '@api'}, async ({ request }) => {
const userId = 1;
const response = await request.delete(`${API_BASE_URL}${USERS_ENDPOINT}/${userId}`);
expect(response.status()).toBe(200);
const body = await response.json();
expect(body).toHaveProperty('id', userId);
expect(body).toHaveProperty('isDeleted', true);
});
test('Remove user twice ',{tag: '@api'}, async ({ request }) => {
const userId = 2;
// First deletion
const response1 = await request.delete(`${API_BASE_URL}${USERS_ENDPOINT}/${userId}`);
expect(response1.status()).toBe(200);
const body1 = await response1.json();
expect(body1).toHaveProperty('id', userId);
// Second deletion attempt (should still return 200, but user is already deleted)
const response2 = await request.delete(`${API_BASE_URL}${USERS_ENDPOINT}/${userId}`);
expect(response2.status()).toBe(200);
const body2 = await response2.json();
expect(body2).toHaveProperty('id', userId);
});
test('Validate body is returned ',{tag: '@api'}, async ({ request }) => {
const userId = 3;
const response = await request.delete(`${API_BASE_URL}${USERS_ENDPOINT}/${userId}`);
expect(response.status()).toBe(200);
const body = await response.json();
// Validate response body structure
expect(body).toBeInstanceOf(Object);
expect(body).toHaveProperty('id');
expect(typeof body.id).toBe('number');
});
});