Skip to content

Commit

Permalink
add tests on teams/tenants
Browse files Browse the repository at this point in the history
  • Loading branch information
Zwiterrion committed Feb 19, 2025
1 parent fa3ccf3 commit ba499c7
Show file tree
Hide file tree
Showing 8 changed files with 129 additions and 37 deletions.
10 changes: 1 addition & 9 deletions otoroshi/javascript/playwright.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export default defineConfig({
timeout: 5000,
forbidOnly: !!process.env.CI,
retries: process.env.CI ? 1 : 0,
workers: process.env.CI ? 1 : undefined,
workers: process.env.CI ? 5 : undefined,
reporter: 'html',
use: {
/* Base URL to use in actions like `await page.goto('/')`. */
Expand All @@ -24,14 +24,6 @@ export default defineConfig({
...devices['Desktop Chrome'],
},
dependencies: ['setup']
},

{
name: 'firefox',
use: {
...devices['Desktop Firefox']
},
dependencies: ['setup']
}
]
});
Expand Down
16 changes: 16 additions & 0 deletions otoroshi/javascript/tests/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Requierements

- You must create a `[email protected]` admin with the following rights
```
[
{
"tenant": "tester:rw",
"teams": [
"tester-team:rw"
]
}
]
```

- You must create a `Tester Organization` with the `tester` id.
- You must create a `Tester Team` with the `tester-team` id inside the `Tester Organization`
25 changes: 0 additions & 25 deletions otoroshi/javascript/tests/playwright/.auth/user.json

This file was deleted.

2 changes: 1 addition & 1 deletion otoroshi/javascript/tests/setup/auth.setup.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { test as setup, expect } from '@playwright/test';
import path from 'path';

const userAuthFile = path.join(__dirname, '../playwright/.auth/user.json');
const userAuthFile = path.join(__dirname, '../playwright/.auth/tester.json');
const adminAuthFile = path.join(__dirname, '../playwright/.auth/admin.json');

setup('authenticate', async ({ page }) => {
Expand Down
60 changes: 60 additions & 0 deletions otoroshi/javascript/tests/spec/entity-location/index.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
const { test, expect } = require('@playwright/test');

let context;

test.beforeAll(async ({ browser }) => {
context = await browser.newContext({ storageState: 'tests/playwright/.auth/admin.json' });
});

test.afterAll(async () => {
await context.close();
});

async function shouldDefaultTeamsAndTenant(path, action = 'add item') {
const page = await context.newPage();
await page.goto(`/bo/dashboard/${path}`);

await page.getByRole('button', { name: action, exact: false }).click();

await expect(page.locator('#content-scroll-container')).toContainText('Default organization - The default organization');
await expect(page.locator('#content-scroll-container')).toContainText('Default team - Default team created for any otoroshi instance');
}

async function shouldDefaultTenantOnTeam() {
const page = await context.newPage();
await page.goto(`/bo/dashboard/teams`);

await page.getByRole('button', { name: 'add item', exact: false }).click();

await expect(page.locator('#content-scroll-container')).toContainText('Default organization - The default organization');
}

async function shouldDefaultTeamsAndTenantOnRoutes() {
const page = await context.newPage();
await page.goto('/');

await page.locator('#navbar').click();

await page.locator('#react-select-2-input').fill('Routes');
await page.getByRole('option', { name: ` Routes` }).locator('div').click();
// await page.getByRole('button', { name: ' Add item' }).click();

await page.getByRole('link', { name: ' Create new route' }).click();
await page.locator('div').filter({ hasText: /^Location$/ }).nth(1).click();

await expect(page.locator('#content-scroll-container')).toContainText('Default organization - The default organization');
await expect(page.locator('#content-scroll-container')).toContainText('Default team - Default team created for any otoroshi instance');
}

test('New Routes got the right entity location', async () => shouldDefaultTeamsAndTenantOnRoutes());
test('New Services got the right entity location', async () => shouldDefaultTeamsAndTenant('services', 'new'));
test('New Data Exporters got the right entity location', async () => shouldDefaultTeamsAndTenant('exporters'));
test('New Apikeys got the right entity location', async () => shouldDefaultTeamsAndTenant('apikeys'));
test('New Auth. modules got the right entity location', async () => shouldDefaultTeamsAndTenant('auth-configs'));
test('New Backends got the right entity location', async () => shouldDefaultTeamsAndTenant('backends'));
test('New Error Templates got the right entity location', async () => shouldDefaultTeamsAndTenant('error-templates'));
test('New JWT verifiers got the right entity location', async () => shouldDefaultTeamsAndTenant('jwt-verifiers'));
test('New Service Groups got the right entity location', async () => shouldDefaultTeamsAndTenant('groups'));
test('New TCP Services got the right entity location', async () => shouldDefaultTeamsAndTenant('tcp/services'));
test('New Teams got the right entity location', async () => shouldDefaultTenantOnTeam());
test('New Wasm Plugins got the right entity location', async () => shouldDefaultTeamsAndTenant('wasm-plugins'));
49 changes: 49 additions & 0 deletions otoroshi/javascript/tests/spec/entity-location/user.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
const { test, expect } = require('@playwright/test');

let context;

test.beforeAll(async ({ browser }) => {
context = await browser.newContext({ storageState: 'tests/playwright/.auth/tester.json' });
});

test.afterAll(async () => {
await context.close();
});

async function shouldDefaultTeamsAndTenant(path, action = 'add item') {
const page = await context.newPage();

await page.goto(`/bo/dashboard/${path}`);

await page.getByRole('button', { name: action, exact: false }).click();

await expect(page.locator('#content-scroll-container')).toContainText('tester-team');
}

async function shouldDefaultTeamsAndTenantOnRoutes() {
const page = await context.newPage();
await page.goto('/');

await page.locator('#navbar').click();

await page.locator('#react-select-2-input').fill('Routes');
await page.getByRole('option', { name: ` Routes` }).locator('div').click();
// await page.getByRole('button', { name: ' Add item' }).click();

await page.getByRole('link', { name: ' Create new route' }).click();
await page.locator('div').filter({ hasText: /^Location$/ }).nth(1).click();


await expect(page.locator('#content-scroll-container')).toContainText('tester-team');
}

test('New Routes got the right entity location', async () => shouldDefaultTeamsAndTenantOnRoutes());
test('New Services got the right entity location', async () => shouldDefaultTeamsAndTenant('services', 'new'));
test('New Data Exporters got the right entity location', async () => shouldDefaultTeamsAndTenant('exporters'));
test('New Apikeys got the right entity location', async () => shouldDefaultTeamsAndTenant('apikeys'));
test('New Auth. modules got the right entity location', async () => shouldDefaultTeamsAndTenant('auth-configs'));
test('New Backends got the right entity location', async () => shouldDefaultTeamsAndTenant('backends'))
test('New JWT verifiers got the right entity location', async () => shouldDefaultTeamsAndTenant('jwt-verifiers'));
test('New Service Groups got the right entity location', async () => shouldDefaultTeamsAndTenant('groups'));
test('New TCP Services got the right entity location', async () => shouldDefaultTeamsAndTenant('tcp/services'));
test('New Wasm Plugins got the right entity location', async () => shouldDefaultTeamsAndTenant('wasm-plugins'));
2 changes: 1 addition & 1 deletion otoroshi/javascript/tests/spec/user/apikeys.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const { test, expect } = require('@playwright/test');
const { SECTIONS } = require('../../utils');

test('create an apikey', async ({ browser }) => {
const context = await browser.newContext({ storageState: 'tests/playwright/.auth/user.json' });
const context = await browser.newContext({ storageState: 'tests/playwright/.auth/tester.json' });
const page = await context.newPage();

await page.goto('/');
Expand Down
2 changes: 1 addition & 1 deletion otoroshi/javascript/tests/spec/user/searchbar.spec.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const { test, expect } = require('@playwright/test');

test('search bar must return entity', async ({ browser }) => {
const context = await browser.newContext({ storageState: 'tests/playwright/.auth/user.json' });
const context = await browser.newContext({ storageState: 'tests/playwright/.auth/tester.json' });
const page = await context.newPage();

await page.goto('/');
Expand Down

0 comments on commit ba499c7

Please sign in to comment.