|
| 1 | +import { CatalogUsersPO } from "../../../support/pageObjects/catalog/catalog-users-obj"; |
| 2 | +import { RhdhAuthUiHack } from "../../../support/api/rhdh-auth-hack"; |
| 3 | +import { Common } from "../../../utils/common"; |
| 4 | +import { test, expect, APIRequestContext, APIResponse, request } from "@playwright/test"; |
| 5 | +import playwrightConfig from "../../../../playwright.config"; |
| 6 | + |
| 7 | +test.describe("Test licensed users info backend plugin", async () => { |
| 8 | + let common: Common; |
| 9 | + let apiToken: string; |
| 10 | + |
| 11 | + const baseRHDHURL: string = playwrightConfig.use.baseURL; |
| 12 | + const pluginAPIURL: string = 'api/licensed-users-info/'; |
| 13 | + |
| 14 | + test.beforeEach(async ({ page }) => { |
| 15 | + common = new Common(page); |
| 16 | + await common.loginAsGuest(); |
| 17 | + await CatalogUsersPO.visitBaseURL(page); |
| 18 | + |
| 19 | + // Get the api token |
| 20 | + const hacker: RhdhAuthUiHack = RhdhAuthUiHack.getInstance(); |
| 21 | + apiToken = await hacker.getApiToken(page); |
| 22 | + }); |
| 23 | + |
| 24 | + test("Test plugin health check endpoint", async () => { |
| 25 | + const requestContext: APIRequestContext = await request.newContext({ |
| 26 | + baseURL: `${baseRHDHURL}/${pluginAPIURL}` |
| 27 | + }); |
| 28 | + |
| 29 | + const response: APIResponse = await requestContext.get("health"); |
| 30 | + const result = await response.json(); |
| 31 | + |
| 32 | + /* |
| 33 | + { status: 'ok' } |
| 34 | + */ |
| 35 | + |
| 36 | + expect(result).toHaveProperty('status'); |
| 37 | + expect(result.status).toBe("ok"); |
| 38 | + }); |
| 39 | + |
| 40 | + test("Test plugin user quantity url", async () => { |
| 41 | + const requestContext: APIRequestContext = await request.newContext({ |
| 42 | + baseURL: `${baseRHDHURL}/${pluginAPIURL}`, |
| 43 | + extraHTTPHeaders: { |
| 44 | + Authorization: apiToken, |
| 45 | + Accept: "application/json", |
| 46 | + } |
| 47 | + }); |
| 48 | + |
| 49 | + const response: APIResponse = await requestContext.get("users/quantity"); |
| 50 | + const result = await response.json(); |
| 51 | + |
| 52 | + /* |
| 53 | + { quantity: '1' } |
| 54 | + */ |
| 55 | + |
| 56 | + expect(result).toHaveProperty('quantity'); |
| 57 | + expect(Number(result.quantity)).toBeGreaterThan(0); |
| 58 | + }); |
| 59 | + |
| 60 | + test("Test plugin users url", async () => { |
| 61 | + const requestContext: APIRequestContext = await request.newContext({ |
| 62 | + baseURL: `${baseRHDHURL}/${pluginAPIURL}`, |
| 63 | + extraHTTPHeaders: { |
| 64 | + Authorization: apiToken, |
| 65 | + Accept: "application/json", |
| 66 | + } |
| 67 | + }); |
| 68 | + |
| 69 | + const response: APIResponse = await requestContext.get("users"); |
| 70 | + const result = await response.json(); |
| 71 | + |
| 72 | + /* |
| 73 | + [ |
| 74 | + { |
| 75 | + userEntityRef: 'user:development/guest', |
| 76 | + lastAuthTime: 'Thu, 17 Jul 2025 17:53:51 GMT' |
| 77 | + } |
| 78 | + ] |
| 79 | + */ |
| 80 | + |
| 81 | + expect(Array.isArray(result)).toBe(true); |
| 82 | + expect(result.length).toBeGreaterThan(0); |
| 83 | + expect(result[0]).toHaveProperty('userEntityRef'); |
| 84 | + expect(result[0]).toHaveProperty('lastAuthTime'); |
| 85 | + expect(result[0].userEntityRef).toContain('user:'); |
| 86 | + }); |
| 87 | + |
| 88 | + test("Test plugin users as a csv url", async () => { |
| 89 | + const requestContext: APIRequestContext = await request.newContext({ |
| 90 | + baseURL: `${baseRHDHURL}/${pluginAPIURL}`, |
| 91 | + extraHTTPHeaders: { |
| 92 | + Authorization: apiToken, |
| 93 | + 'Content-Type': 'text/csv' |
| 94 | + } |
| 95 | + }); |
| 96 | + |
| 97 | + const response: APIResponse = await requestContext.get("users"); |
| 98 | + |
| 99 | + // 'content-type': 'text/csv; charset=utf-8', |
| 100 | + expect(response.headers()["content-type"]).toContain('text/csv'); |
| 101 | + |
| 102 | + // 'content-disposition': 'attachment; filename="data.csv"', |
| 103 | + expect(response.headers()["content-disposition"]).toBe("attachment; filename=\"data.csv\""); |
| 104 | + |
| 105 | + const result = await response.text(); |
| 106 | + /* |
| 107 | + userEntityRef,displayName,email,lastAuthTime |
| 108 | + user:development/guest,undefined,undefined,"Fri, 18 Jul 2025 12:41:47 GMT" |
| 109 | + */ |
| 110 | + const splitText = result.split('\n'); |
| 111 | + const csvHeaders = splitText[0]; |
| 112 | + const csvData = splitText[1]; |
| 113 | + |
| 114 | + expect(csvHeaders).toContain("userEntityRef,displayName,email,lastAuthTime"); |
| 115 | + expect(csvData).toContain("user:"); |
| 116 | + }); |
| 117 | +}); |
0 commit comments