Skip to content

Commit

Permalink
FIX playwright tests
Browse files Browse the repository at this point in the history
  • Loading branch information
quentinovega committed Oct 8, 2024
1 parent bd5a612 commit ba6d95c
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 79 deletions.
35 changes: 22 additions & 13 deletions daikoku/javascript/tests/connectedUser.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ test('Create & manage API', async ({ page }) => {
* subscribe on second API and aggregate it
* delete a key
*/
test('aggregation mode', async ({ page, request }) => {
test('aggregation mode', async ({ page, request, context }) => {
await request.post('http://localhost:9000/admin-api/usage-plans', {
headers: {
"Authorization": `Basic ${btoa(adminApikeyId + ":" + adminApikeySecret)}`
Expand Down Expand Up @@ -368,6 +368,8 @@ test('aggregation mode', async ({ page, request }) => {
]
})

await context.grantPermissions(["clipboard-read", "clipboard-write"]);

//login
await page.goto(`http://localhost:${exposedPort}/apis`);
await page.getByRole('img', { name: 'user menu' }).click();
Expand Down Expand Up @@ -395,16 +397,18 @@ test('aggregation mode', async ({ page, request }) => {
await page.getByRole('link', { name: 'APIs list' }).click();
await page.locator('.top__container').filter({ hasText: 'Your teams' })
.getByText('Consumers').click()
// await page.getByLabel('Notifications alt+T').getByRole('button').click();
await page.getByText('API keys', { exact: true }).click();
await page.getByRole('row', { name: 'test API 2 1.0.0' }).getByLabel('View APIkeys').click();

//get the client id value to check
const apikey = await page.locator('.api-subscription__infos__value').innerText()
await page.getByRole('button', { name: 'clientId:clientToken' }).click();
const apikey = await page.evaluate(() => navigator.clipboard.readText());

await page.getByText('API keys', { exact: true }).click();
await page.getByRole('row', { name: 'test API 2.0.0' }).getByLabel('view APikey').click();
await expect(page.locator('.api-subscription__infos__value').first()).toHaveText(apikey);
await page.getByRole('button', { name: 'clientId:clientToken' }).click();
const apikey2 = await page.evaluate(() => navigator.clipboard.readText());
await expect(apikey2).toBe(apikey)
await page.locator('.api-subscription').locator('.dropdown').click();
await page.getByText('Show aggregate').click();
await expect(page.getByRole('link', { name: 'test API 2/test plan' })).toBeVisible();
Expand All @@ -413,16 +417,21 @@ test('aggregation mode', async ({ page, request }) => {
await page.getByRole('row', { name: 'test API 2 1.0.0' }).getByLabel('view APikey').click();
await page.locator('.api-subscription').locator('.dropdown').click();
await page.getByText('Extract from aggregate').click();
// await page.getByRole('button', { name: 'make unique' }).click();
await expect(page.getByRole('paragraph')).toContainText('Are you sure to make this API key unique and separate from his parent plan?');
await page.getByRole('button', { name: 'Ok', exact: true }).click();
await expect(page.locator('.api-subscription__infos__value').first()).not.toHaveText(apikey);
await page.waitForResponse(r => r.url().includes('/_makeUnique') && r.status() === 200);
await page.reload();

await page.getByRole('button', { name: 'clientId:clientToken' }).click();
const apikeyUniq = await page.evaluate(() => navigator.clipboard.readText());
console.log({apikey, apikey2, apikeyUniq})
await expect(apikeyUniq).not.toBe(apikey)


// //test archive apikey & clean archive apikeys
await page.locator('.api-subscription').locator('.dropdown').click();
await page.getByText('Disable subscription').click();
await expect(page.locator('.api-subscription__value__type')).toHaveText('Disabled')
// await expect(page.getByRole('button', { name: 'Enable subscription' })).toBeVisible();

await page.locator('.api-subscription').locator('.dropdown').click();
await page.getByText('Delete').click();
Expand Down Expand Up @@ -586,7 +595,8 @@ test('Filter API List', async ({ page, request }) => {
})


test('transfer an api subscription', async ({ page }) => {
test('transfer an api subscription', async ({ page, context }) => {
await context.grantPermissions(["clipboard-read", "clipboard-write"]);
await page.goto('http://localhost:5173/apis');
await page.getByRole('img', { name: 'user menu' }).click();
await page.getByPlaceholder('Email address').fill('tester@foo.bar');
Expand All @@ -602,17 +612,16 @@ test('transfer an api subscription', async ({ page }) => {
await page.locator('div').filter({ hasText: /^fake prod plan/ }).getByRole('button').click();
await page.getByText('Consumers').click();
await page.getByLabel('Notifications').getByRole('img').nth(1).click();
const apikey = await page.locator('.api-subscription__infos__value').innerText();


await page.locator('.api-subscription__icon').isVisible();
// await page.locator('.api-subscription__infos__value').innerText();
await page.getByRole('button', { name: 'clientId:clientToken' }).click();
const apikey = await page.evaluate(() => navigator.clipboard.readText());

await page.locator('#dropdownMenuButton').click();
await page.getByText('Transfer subscription').click();
await page.getByText('Display link').click();
const link = await page.locator('.api-susbcription__display-link').innerText();



await page.goto(link);
await page.getByText('Testers').click();
await page.getByRole('button', { name: 'Confirm transfer' }).click();
Expand Down
73 changes: 7 additions & 66 deletions daikoku/javascript/tests/envMode.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,73 +95,14 @@ test('aggregation security works', async ({ page, request }) => {
await expect(page.getByRole('cell', { name: 'Child API' })).toBeVisible();
await expect(page.getByRole('cell', { name: 'Parent API' })).toBeVisible();
await page.getByRole('row', { name: 'Parent API 1.0.0 View API' }).getByLabel('View APIkeys').click();
await expect(page.getByText('prod')).toBeVisible();
// await expect(page.getByText('prod')).toBeVisible();
await expect(page.locator('.api-subscription__infos__name')).toHaveText('prod')
await page.getByText('API keys', { exact: true }).click();
await page.getByRole('cell', { name: 'Child API' }).click();
await page.getByRole('row', { name: 'Child API 1.0.0 View API View' }).getByLabel('View APIkeys').click();
await expect(page.getByText('dev')).toBeVisible();
await expect(page.getByText('prod')).toBeVisible();



// //subscribe first API
// await page.getByRole('heading', { name: 'Parent API', exact: true }).click();
// await page.getByText('Environments').click();
// await page.locator('.usage-plan__card').filter({ hasText: 'prod' }).getByRole('button').click();
// await page.locator('div').filter({ hasText: /^Consumers$/ }).click();
// await page.getByRole('link', { name: 'APIs list' }).click();

// //subscribe second api with aggregation
// await page.getByRole('heading', { name: 'Child API' }).click();
// await page.getByText('Environments').click();
// await page.locator('.usage-plan__card').filter({ hasText: 'dev' }).getByRole('button').click();
// await page.locator('.team-selection').filter({ hasText: 'Consumers' }).click();
// //no possibility to extends existing key


// //subscribe second api with aggregation
// await page.getByRole('link', { name: 'APIs list' }).click();
// await page.getByRole('heading', { name: 'Child API' }).click();
// await page.getByText('Environments').click();
// await page.locator('.usage-plan__card').filter({ hasText: 'prod' }).getByRole('button').click();
// await page.locator('.team-selection').filter({ hasText: 'Consumers' }).click();
// await page.getByRole('button', { name: ' Subscribe using an existing' }).click();
// await page.getByText('parent API/prod').click();

// //go to subscriptions
// await page.getByRole('link', { name: 'APIs list' }).click();
// await page.locator('.top__container').filter({ hasText: 'Your teams' })
// .getByText('Consumers').click()
// // await page.getByLabel('Notifications alt+T').getByRole('button').click();
// await page.getByText('API keys', { exact: true }).click();
// await page.getByRole('row', { name: 'test API 2 1.0.0' }).getByLabel('View APIkeys').click();

// //get the client id value to check
// const clientId = await page.getByLabel('Client Id').inputValue()

// await page.getByText('API keys', { exact: true }).click();
// await page.getByRole('row', { name: 'test API 2.0.0' }).getByLabel('view APikey').click();
// await expect(page.getByLabel('Client Id').first()).toHaveValue(clientId);
// await page.getByRole('button', { name: 'Show aggregate subscriptions' }).click();
// await expect(page.getByRole('link', { name: 'test API 2/test plan' })).toBeVisible();
// await page.getByText('API keys', { exact: true }).click();
// await page.getByRole('row', { name: 'test API 2 1.0.0' }).getByLabel('view APikey').click();
// await page.getByRole('button', { name: 'make unique' }).click();
// await expect(page.getByRole('paragraph')).toContainText('Are you sure to make this API key unique and separate from his parent plan?');
// await page.getByRole('button', { name: 'Ok' }).click();
// await expect(page.getByLabel('Client Id').first()).not.toHaveValue(clientId);

// // //test archive apikey & clean archive apikeys
// await page.getByRole('button', { name: 'Disable subscription' }).click();
// await expect(page.getByRole('button', { name: 'Enable subscription' })).toBeVisible();

// await page.getByLabel('Delete').click();
// await expect(page.locator('h5')).toContainText('Confirm Deletion');
// await page.getByLabel('To confirm the deletion,').fill('test API 2/test plan');
// await page.getByRole('button', { name: 'Confirm' }).click();
// await page.getByText('API keys', { exact: true }).click();
// await expect(page.getByRole('row', { name: 'test API 2 1.0.0' })).toBeHidden




const apiKeys = await page.locator('.api-subscription__infos__name');
expect(apiKeys).toHaveCount(2);
expect(apiKeys.nth(0)).toHaveText('dev');
expect(apiKeys.nth(1)).toHaveText('prod');
})

0 comments on commit ba6d95c

Please sign in to comment.