mirror of
https://github.com/grafana/grafana.git
synced 2024-11-22 08:56:43 -06:00
remove e2e-api-tests + axios dependency (#58148)
This commit is contained in:
parent
0792ff8e20
commit
c1c8dc8749
@ -1,7 +0,0 @@
|
||||
import * as setup from './setup';
|
||||
|
||||
describe.skip('clear state', () => {
|
||||
it('will clear state', () => {
|
||||
return setup.clearState();
|
||||
});
|
||||
});
|
@ -1,30 +0,0 @@
|
||||
const axios = require('axios');
|
||||
|
||||
export function getClient(options) {
|
||||
return axios.create({
|
||||
baseURL: 'http://localhost:3000',
|
||||
timeout: 1000,
|
||||
auth: {
|
||||
username: options.username,
|
||||
password: options.password,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export function getAdminClient() {
|
||||
return getClient({
|
||||
username: 'admin',
|
||||
password: 'admin',
|
||||
});
|
||||
}
|
||||
|
||||
let client = getAdminClient();
|
||||
|
||||
client.callAs = function (user) {
|
||||
return getClient({
|
||||
username: user.login,
|
||||
password: 'password',
|
||||
});
|
||||
};
|
||||
|
||||
export default client;
|
@ -1,45 +0,0 @@
|
||||
import client from './client';
|
||||
import * as setup from './setup';
|
||||
|
||||
describe('/api/dashboards', () => {
|
||||
let state = {};
|
||||
|
||||
beforeAll(async () => {
|
||||
state = await setup.ensureState({
|
||||
orgName: 'api-test-org',
|
||||
users: [
|
||||
{ user: setup.admin, role: 'Admin' },
|
||||
{ user: setup.editor, role: 'Editor' },
|
||||
{ user: setup.viewer, role: 'Viewer' },
|
||||
],
|
||||
admin: setup.admin,
|
||||
dashboards: [
|
||||
{
|
||||
title: 'aaa',
|
||||
uid: 'aaa',
|
||||
},
|
||||
{
|
||||
title: 'bbb',
|
||||
uid: 'bbb',
|
||||
},
|
||||
],
|
||||
});
|
||||
});
|
||||
|
||||
describe('With admin user', () => {
|
||||
it('can delete dashboard', async () => {
|
||||
let rsp = await client.callAs(setup.admin).delete(`/api/dashboards/uid/aaa`);
|
||||
expect(rsp.data.title).toBe('aaa');
|
||||
});
|
||||
});
|
||||
|
||||
describe('With viewer user', () => {
|
||||
it('Cannot delete dashboard', async () => {
|
||||
let rsp = await setup.expectError(() => {
|
||||
return client.callAs(setup.viewer).delete(`/api/dashboards/uid/bbb`);
|
||||
});
|
||||
|
||||
expect(rsp.response.status).toBe(403);
|
||||
});
|
||||
});
|
||||
});
|
@ -1,76 +0,0 @@
|
||||
import client from './client';
|
||||
import * as setup from './setup';
|
||||
|
||||
describe('/api/folders', () => {
|
||||
beforeAll(async () => {
|
||||
await setup.ensureState({
|
||||
orgName: 'api-test-org',
|
||||
users: [
|
||||
{ user: setup.admin, role: 'Admin' },
|
||||
{ user: setup.editor, role: 'Editor' },
|
||||
{ user: setup.viewer, role: 'Viewer' },
|
||||
],
|
||||
admin: setup.admin,
|
||||
folders: [
|
||||
{
|
||||
title: 'Folder 1',
|
||||
uid: 'f-01',
|
||||
},
|
||||
{
|
||||
title: 'Folder 2',
|
||||
uid: 'f-02',
|
||||
},
|
||||
{
|
||||
title: 'Folder 3',
|
||||
uid: 'f-03',
|
||||
},
|
||||
],
|
||||
});
|
||||
});
|
||||
|
||||
describe('With admin user', () => {
|
||||
it('can delete folder', async () => {
|
||||
let rsp = await client.callAs(setup.admin).delete(`/api/folders/f-01`);
|
||||
expect(rsp.data.title).toBe('Folder 1');
|
||||
});
|
||||
|
||||
it('can update folder', async () => {
|
||||
let rsp = await client.callAs(setup.admin).put(`/api/folders/f-02`, {
|
||||
uid: 'f-02',
|
||||
title: 'Folder 2 upd',
|
||||
overwrite: true,
|
||||
});
|
||||
expect(rsp.data.title).toBe('Folder 2 upd');
|
||||
});
|
||||
|
||||
it('can update folder uid', async () => {
|
||||
let rsp = await client.callAs(setup.admin).put(`/api/folders/f-03`, {
|
||||
uid: 'f-03-upd',
|
||||
title: 'Folder 3 upd',
|
||||
overwrite: true,
|
||||
});
|
||||
expect(rsp.data.uid).toBe('f-03-upd');
|
||||
expect(rsp.data.title).toBe('Folder 3 upd');
|
||||
});
|
||||
});
|
||||
|
||||
describe('With viewer user', () => {
|
||||
it('Cannot delete folder', async () => {
|
||||
let rsp = await setup.expectError(() => {
|
||||
return client.callAs(setup.viewer).delete(`/api/folders/f-02`);
|
||||
});
|
||||
expect(rsp.response.status).toBe(403);
|
||||
});
|
||||
|
||||
it('Cannot update folder', async () => {
|
||||
let rsp = await setup.expectError(() => {
|
||||
return client.callAs(setup.viewer).put(`/api/folders/f-02`, {
|
||||
uid: 'f-02',
|
||||
title: 'Folder 2 upd',
|
||||
overwrite: true,
|
||||
});
|
||||
});
|
||||
expect(rsp.response.status).toBe(403);
|
||||
});
|
||||
});
|
||||
});
|
@ -1,15 +0,0 @@
|
||||
module.exports = {
|
||||
verbose: true,
|
||||
globals: {
|
||||
'ts-jest': {
|
||||
tsConfigFile: 'tsconfig.json',
|
||||
},
|
||||
},
|
||||
transform: {
|
||||
'^.+\\.tsx?$': '<rootDir>/../../node_modules/ts-jest/preprocessor.js',
|
||||
},
|
||||
moduleDirectories: ['node_modules'],
|
||||
testRegex: '(\\.|/)(test)\\.ts$',
|
||||
testEnvironment: 'node',
|
||||
moduleFileExtensions: ['ts', 'js', 'json'],
|
||||
};
|
@ -1,27 +0,0 @@
|
||||
import client from './client';
|
||||
import * as setup from './setup';
|
||||
|
||||
describe('GET /api/search', () => {
|
||||
const state = {};
|
||||
|
||||
beforeAll(async () => {
|
||||
state = await setup.ensureState({
|
||||
orgName: 'api-test-org',
|
||||
users: [{ user: setup.admin, role: 'Admin' }],
|
||||
admin: setup.admin,
|
||||
dashboards: [
|
||||
{
|
||||
title: 'Dashboard in root no permissions',
|
||||
uid: 'AAA',
|
||||
},
|
||||
],
|
||||
});
|
||||
});
|
||||
|
||||
describe('With admin user', () => {
|
||||
it('should return all dashboards', async () => {
|
||||
let rsp = await client.callAs(state.admin).get('/api/search');
|
||||
expect(rsp.data).toHaveLength(1);
|
||||
});
|
||||
});
|
||||
});
|
@ -1,123 +0,0 @@
|
||||
import client from './client';
|
||||
import _ from 'lodash;';
|
||||
|
||||
export const editor = {
|
||||
email: 'api-test-editor@grafana.com',
|
||||
login: 'api-test-editor',
|
||||
password: 'password',
|
||||
name: 'Api Test Editor',
|
||||
};
|
||||
|
||||
export const admin = {
|
||||
email: 'api-test-admin@grafana.com',
|
||||
login: 'api-test-admin',
|
||||
password: 'password',
|
||||
name: 'Api Test Super',
|
||||
};
|
||||
|
||||
export const viewer = {
|
||||
email: 'api-test-viewer@grafana.com',
|
||||
login: 'api-test-viewer',
|
||||
password: 'password',
|
||||
name: 'Api Test Viewer',
|
||||
};
|
||||
|
||||
export async function expectError(callback) {
|
||||
try {
|
||||
let rsp = await callback();
|
||||
return rsp;
|
||||
} catch (err) {
|
||||
return err;
|
||||
}
|
||||
|
||||
return rsp;
|
||||
}
|
||||
|
||||
// deletes org if it's already there
|
||||
export async function getOrg(orgName) {
|
||||
try {
|
||||
const rsp = await client.get(`/api/orgs/name/${orgName}`);
|
||||
await client.delete(`/api/orgs/${rsp.data.id}`);
|
||||
} catch {}
|
||||
|
||||
const rsp = await client.post(`/api/orgs`, { name: orgName });
|
||||
return { name: orgName, id: rsp.data.orgId };
|
||||
}
|
||||
|
||||
export async function getUser(user) {
|
||||
const search = await client.get('/api/users/search', {
|
||||
params: { query: user.login },
|
||||
});
|
||||
|
||||
if (search.data.totalCount === 1) {
|
||||
user.id = search.data.users[0].id;
|
||||
return user;
|
||||
}
|
||||
|
||||
const rsp = await client.post('/api/admin/users', user);
|
||||
user.id = rsp.data.id;
|
||||
|
||||
return user;
|
||||
}
|
||||
|
||||
export async function addUserToOrg(org, user, role) {
|
||||
const rsp = await client.post(`/api/orgs/${org.id}/users`, {
|
||||
loginOrEmail: user.login,
|
||||
role: role,
|
||||
});
|
||||
|
||||
return rsp.data;
|
||||
}
|
||||
|
||||
export async function clearState() {
|
||||
const admin = await getUser(adminUser);
|
||||
const rsp = await client.delete(`/api/admin/users/${admin.id}`);
|
||||
return rsp.data;
|
||||
}
|
||||
|
||||
export async function setUsingOrg(user, org) {
|
||||
await client.callAs(user).post(`/api/user/using/${org.id}`);
|
||||
}
|
||||
|
||||
export async function createDashboard(user, dashboard) {
|
||||
const rsp = await client.callAs(user).post(`/api/dashboards/db`, {
|
||||
dashboard: dashboard,
|
||||
overwrite: true,
|
||||
});
|
||||
dashboard.id = rsp.data.id;
|
||||
dashboard.url = rsp.data.url;
|
||||
|
||||
return dashboard;
|
||||
}
|
||||
|
||||
export async function createFolder(user, folder) {
|
||||
const rsp = await client.callAs(user).post(`/api/folders`, {
|
||||
uid: folder.uid,
|
||||
title: folder.title,
|
||||
overwrite: true,
|
||||
});
|
||||
folder.id = rsp.id;
|
||||
folder.url = rsp.url;
|
||||
|
||||
return folder;
|
||||
}
|
||||
|
||||
export async function ensureState(state) {
|
||||
const org = await getOrg(state.orgName);
|
||||
|
||||
for (let orgUser of state.users) {
|
||||
const user = await getUser(orgUser.user);
|
||||
await addUserToOrg(org, user, orgUser.role);
|
||||
await setUsingOrg(user, org);
|
||||
}
|
||||
|
||||
for (let dashboard of state.dashboards || []) {
|
||||
await createDashboard(state.admin, dashboard);
|
||||
}
|
||||
|
||||
for (let folder of state.folders || []) {
|
||||
await createFolder(state.admin, folder);
|
||||
}
|
||||
|
||||
return state;
|
||||
}
|
@ -1,21 +0,0 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"allowSyntheticDefaultImports": true,
|
||||
"declaration": false,
|
||||
"emitDecoratorMetadata": false,
|
||||
"experimentalDecorators": true,
|
||||
"inlineSourceMap": false,
|
||||
"lib": ["es6"],
|
||||
"module": "commonjs",
|
||||
"moduleResolution": "node",
|
||||
"noEmitOnError": false,
|
||||
"noImplicitAny": false,
|
||||
"noImplicitReturns": true,
|
||||
"noImplicitThis": false,
|
||||
"noImplicitUseStrict": false,
|
||||
"noUnusedLocals": true,
|
||||
"sourceMap": true,
|
||||
"target": "es6"
|
||||
},
|
||||
"include": ["*.ts", "**/*.ts"]
|
||||
}
|
@ -1,22 +0,0 @@
|
||||
import client from './client';
|
||||
import * as setup from './setup';
|
||||
|
||||
describe('GET /api/user', () => {
|
||||
it('should return current authed user', async () => {
|
||||
let rsp = await client.get('/api/user');
|
||||
expect(rsp.data.login).toBe('admin');
|
||||
});
|
||||
});
|
||||
|
||||
describe('PUT /api/user', () => {
|
||||
it('should update current authed user', async () => {
|
||||
const user = await setup.getUser(setup.editor);
|
||||
user.name = 'Updated via test';
|
||||
|
||||
const rsp = await client.callAs(user).put('/api/user', user);
|
||||
expect(rsp.data.message).toBe('User updated');
|
||||
|
||||
const updated = await client.callAs(user).get('/api/user');
|
||||
expect(updated.data.name).toBe('Updated via test');
|
||||
});
|
||||
});
|
@ -6,7 +6,6 @@
|
||||
"version": "9.3.0-pre",
|
||||
"repository": "github:grafana/grafana",
|
||||
"scripts": {
|
||||
"api-tests": "jest --notify --watch --config=devenv/e2e-api-tests/jest.js",
|
||||
"build": "yarn i18n:compile && NODE_ENV=production webpack --config scripts/webpack/webpack.prod.js",
|
||||
"build:nominify": "yarn run build --env noMinify=1",
|
||||
"dev": "yarn i18n:compile && webpack --progress --color --config scripts/webpack/webpack.dev.js",
|
||||
@ -166,7 +165,6 @@
|
||||
"@typescript-eslint/parser": "5.42.0",
|
||||
"@wojtekmaj/enzyme-adapter-react-17": "0.6.7",
|
||||
"autoprefixer": "10.4.13",
|
||||
"axios": "0.27.2",
|
||||
"babel-jest": "28.1.3",
|
||||
"babel-loader": "9.0.1",
|
||||
"babel-plugin-angularjs-annotate": "0.10.0",
|
||||
|
21
yarn.lock
21
yarn.lock
@ -13915,16 +13915,6 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"axios@npm:0.27.2":
|
||||
version: 0.27.2
|
||||
resolution: "axios@npm:0.27.2"
|
||||
dependencies:
|
||||
follow-redirects: ^1.14.9
|
||||
form-data: ^4.0.0
|
||||
checksum: 38cb7540465fe8c4102850c4368053c21683af85c5fdf0ea619f9628abbcb59415d1e22ebc8a6390d2bbc9b58a9806c874f139767389c862ec9b772235f06854
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"axios@npm:^0.25.0":
|
||||
version: 0.25.0
|
||||
resolution: "axios@npm:0.25.0"
|
||||
@ -20526,16 +20516,6 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"follow-redirects@npm:^1.14.9":
|
||||
version: 1.15.0
|
||||
resolution: "follow-redirects@npm:1.15.0"
|
||||
peerDependenciesMeta:
|
||||
debug:
|
||||
optional: true
|
||||
checksum: eaec81c3e0ae57aae2422e38ad3539d0e7279b3a63f9681eeea319bb683dea67502c4e097136b8ce9721542b4e236e092b6b49e34e326cdd7733c274f0a3f378
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"for-in@npm:^1.0.2":
|
||||
version: 1.0.2
|
||||
resolution: "for-in@npm:1.0.2"
|
||||
@ -21665,7 +21645,6 @@ __metadata:
|
||||
ansicolor: 1.1.100
|
||||
app: "link:./public/app"
|
||||
autoprefixer: 10.4.13
|
||||
axios: 0.27.2
|
||||
babel-jest: 28.1.3
|
||||
babel-loader: 9.0.1
|
||||
babel-plugin-angularjs-annotate: 0.10.0
|
||||
|
Loading…
Reference in New Issue
Block a user