Browse Source

test(api): add tests for new apis

Signed-off-by: Pranav C <pranavxc@gmail.com>
pull/4134/head
Pranav C 2 years ago
parent
commit
2d3cccabfc
  1. 2
      packages/nc-gui/components/admin/Token.vue
  2. 17
      packages/nc-gui/components/admin/User.vue
  3. 2
      packages/nocodb/tests/unit/rest/index.test.ts
  4. 2
      packages/nocodb/tests/unit/rest/tests/auth.test.ts
  5. 173
      packages/nocodb/tests/unit/rest/tests/org.test.ts

2
packages/nc-gui/components/admin/Token.vue

@ -139,7 +139,7 @@ const copyToken = (token: string | undefined) => {
<!-- Token --> <!-- Token -->
<a-table-column key="token" :title="$t('labels.token')" data-index="token"> <a-table-column key="token" :title="$t('labels.token')" data-index="token">
<template #default="{ text, record }"> <template #default="{ text, record }">
<div> <div class="w-[320px]">
<span v-if="record.show">{{ text }}</span> <span v-if="record.show">{{ text }}</span>
<span v-else>****************************************</span> <span v-else>****************************************</span>
</div> </div>

17
packages/nc-gui/components/admin/User.vue

@ -118,8 +118,8 @@ const copyInviteUrl = (user: User) => {
</a-tab-pane> </a-tab-pane>
</a-tabs> </a-tabs>
<template v-if="selectedTabKey === 0"> <template v-if="selectedTabKey === 0">
<!-- <div class="text-xl mt-4">User Management</div> --> <div class="text-xl mt-4">User Management</div>
<!-- <a-divider class="!my-3" /> --> <a-divider class="!my-3" />
<div class="max-w-[900px] mx-auto p-4"> <div class="max-w-[900px] mx-auto p-4">
<div class="py-2 flex gap-4 items-center"> <div class="py-2 flex gap-4 items-center">
<a-input-search <a-input-search
@ -132,7 +132,7 @@ const copyInviteUrl = (user: User) => {
> >
</a-input-search> </a-input-search>
<div class="flex-grow"></div> <div class="flex-grow"></div>
<MdiReload @click="loadUsers" class="cursor-pointer"/> <MdiReload @click="loadUsers" class="cursor-pointer" />
<a-button size="small" @click="showUserModal = true"> <a-button size="small" @click="showUserModal = true">
<div class="flex items-center gap-1"> <div class="flex items-center gap-1">
<MdiAdd /> <MdiAdd />
@ -176,14 +176,14 @@ const copyInviteUrl = (user: User) => {
<a-select-option :value="Role.OrgLevelCreator" :label="$t(`objects.roleType.orgLevelCreator`)"> <a-select-option :value="Role.OrgLevelCreator" :label="$t(`objects.roleType.orgLevelCreator`)">
<div>{{ $t(`objects.roleType.orgLevelCreator`) }}</div> <div>{{ $t(`objects.roleType.orgLevelCreator`) }}</div>
<span class="text-gray-500 text-xs whitespace-normal" <span class="text-gray-500 text-xs whitespace-normal"
>Creator can create new projects and access any invited project.</span >Creator can create new projects and access any invited project.</span
> >
</a-select-option> </a-select-option>
<a-select-option :value="Role.OrgLevelViewer" :label="$t(`objects.roleType.orgLevelViewer`)"> <a-select-option :value="Role.OrgLevelViewer" :label="$t(`objects.roleType.orgLevelViewer`)">
<div>{{ $t(`objects.roleType.orgLevelViewer`) }}</div> <div>{{ $t(`objects.roleType.orgLevelViewer`) }}</div>
<span class="text-gray-500 text-xs whitespace-normal" <span class="text-gray-500 text-xs whitespace-normal"
>Viewer is not allowed to create new projects but they can access any invited project.</span >Viewer is not allowed to create new projects but they can access any invited project.</span
> >
</a-select-option> </a-select-option>
</a-select> </a-select>
@ -207,7 +207,8 @@ const copyInviteUrl = (user: User) => {
<div v-if="!record.roles.includes('super')" class="flex items-center gap-2"> <div v-if="!record.roles.includes('super')" class="flex items-center gap-2">
<MdiDeleteOutline class="nc-action-btn cursor-pointer" @click="deleteUser(text)" /> <MdiDeleteOutline class="nc-action-btn cursor-pointer" @click="deleteUser(text)" />
<a-dropdown :trigger="['click']" class="flex" placement="bottomRight" overlay-class-name="nc-dropdown-user-mgmt"> <a-dropdown :trigger="['click']" class="flex" placement="bottomRight"
overlay-class-name="nc-dropdown-user-mgmt">
<div class="flex flex-row items-center"> <div class="flex flex-row items-center">
<a-button type="text" class="!px-0"> <a-button type="text" class="!px-0">
<div class="flex flex-row items-center h-[1.2rem]"> <div class="flex flex-row items-center h-[1.2rem]">
@ -250,8 +251,8 @@ const copyInviteUrl = (user: User) => {
</div> </div>
</template> </template>
<template v-else> <template v-else>
<!-- <div class="text-xl mt-4">Settings</div> --> <div class="text-xl mt-4">Settings</div>
<!-- <a-divider class="!my-3" /> --> <a-divider class="!my-3" />
<a-form-item> <a-form-item>
<a-checkbox name="virtual">Enable user signup</a-checkbox> <a-checkbox name="virtual">Enable user signup</a-checkbox>
</a-form-item> </a-form-item>

2
packages/nocodb/tests/unit/rest/index.test.ts

@ -1,5 +1,6 @@
import 'mocha'; import 'mocha';
import authTests from './tests/auth.test'; import authTests from './tests/auth.test';
import orgTests from './tests/org.test';
import projectTests from './tests/project.test'; import projectTests from './tests/project.test';
import tableTests from './tests/table.test'; import tableTests from './tests/table.test';
import tableRowTests from './tests/tableRow.test'; import tableRowTests from './tests/tableRow.test';
@ -7,6 +8,7 @@ import viewRowTests from './tests/viewRow.test';
function restTests() { function restTests() {
authTests(); authTests();
orgTests();
projectTests(); projectTests();
tableTests(); tableTests();
tableRowTests(); tableRowTests();

2
packages/nocodb/tests/unit/rest/tests/auth.test.ts

@ -4,7 +4,7 @@ import request from 'supertest';
import init from '../../init'; import init from '../../init';
import { defaultUserArgs } from '../../factory/user'; import { defaultUserArgs } from '../../factory/user';
function authTests() { function orgTests() {
let context; let context;
beforeEach(async function () { beforeEach(async function () {

173
packages/nocodb/tests/unit/rest/tests/org.test.ts

@ -0,0 +1,173 @@
import { expect } from 'chai'
import 'mocha'
import request from 'supertest'
import { OrgUserRoles } from '../../../../src/enums/OrgUserRoles'
import init from '../../init'
function authTests() {
let context
beforeEach(async function() {
context = await init()
})
it('Get users list', async () => {
const response = await request(context.app)
.get('/api/v1/users')
.set('xc-auth', context.token)
.expect(200)
expect(response.body).to.have.keys(['list', 'pageInfo'])
expect(response.body.list).to.have.length(1)
})
it('Invite a new user', async () => {
const response = await request(context.app)
.post('/api/v1/users')
.set('xc-auth', context.token).send({ email: 'a@nocodb.com' })
.expect(200)
console.log(response.body)
expect(response.body).to.have.property('invite_token').to.be.a('string')
// todo: verify invite token
})
it('Update user role', async () => {
const email = 'a@nocodb.com'
// invite a user
await request(context.app)
.post('/api/v1/users')
.set('xc-auth', context.token).send({ email })
.expect(200)
const response = await request(context.app)
.get('/api/v1/users')
.set('xc-auth', context.token)
.expect(200)
expect(response.body.list).to.have.length(2)
const user = response.body.list.find(u => u.email === email)
expect(user).to.have.property('roles').to.be.equal(OrgUserRoles.VIEWER)
await request(context.app)
.patch('/api/v1/users/' + user.id)
.set('xc-auth', context.token)
.send({ roles: OrgUserRoles.CREATOR })
.expect(200)
const response2 = await request(context.app)
.get('/api/v1/users')
.set('xc-auth', context.token)
.expect(200)
expect(response2.body.list).to.have.length(2)
const user2 = response2.body.list.find(u => u.email === email)
expect(user2).to.have.property('roles').to.be.equal(OrgUserRoles.CREATOR)
})
it('Remove user', async () => {
const email = 'a@nocodb.com'
// invite a user
await request(context.app)
.post('/api/v1/users')
.set('xc-auth', context.token).send({ email })
.expect(200)
const response = await request(context.app)
.get('/api/v1/users')
.set('xc-auth', context.token)
.expect(200)
expect(response.body.list).to.have.length(2)
const user = response.body.list.find(u => u.email === email)
expect(user).to.have.property('roles').to.be.equal(OrgUserRoles.VIEWER)
await request(context.app)
.delete('/api/v1/users/' + user.id)
.set('xc-auth', context.token)
.expect(200)
const response2 = await request(context.app)
.get('/api/v1/users')
.set('xc-auth', context.token)
.expect(200)
expect(response2.body.list).to.have.length(1)
})
it('Get token list', async () => {
const response = await request(context.app)
.get('/api/v1/tokens')
.set('xc-auth', context.token)
.expect(200)
expect(response.body).to.have.keys(['list', 'pageInfo'])
expect(response.body.list).to.have.length(0)
})
it('Generate token', async () => {
const r = await request(context.app)
.post('/api/v1/tokens')
.set('xc-auth', context.token)
.send({ description: 'test' })
.expect(200)
const response = await request(context.app)
.get('/api/v1/tokens')
.set('xc-auth', context.token)
.expect(200)
expect(response.body).to.have.keys(['list', 'pageInfo'])
expect(response.body.list).to.have.length(1)
expect(response.body.list[0]).to.have.property('token').to.be.a('string')
expect(response.body.list[0]).to.have.property('description').to.be.a('string').to.be.eq('test')
})
it.only('Delete token', async () => {
const r = await request(context.app)
.post('/api/v1/tokens')
.set('xc-auth', context.token)
.send({ description: 'test' })
.expect(200)
let response = await request(context.app)
.get('/api/v1/tokens')
.set('xc-auth', context.token)
.expect(200)
expect(response.body).to.have.keys(['list', 'pageInfo'])
expect(response.body.list).to.have.length(1)
await request(context.app)
.delete('/api/v1/tokens/' + r.body.token)
.set('xc-auth', context.token)
.expect(200)
response = await request(context.app)
.get('/api/v1/tokens')
.set('xc-auth', context.token)
.expect(200)
expect(response.body).to.have.keys(['list', 'pageInfo'])
expect(response.body.list).to.have.length(0)
})
}
export default function() {
describe('Organisation', authTests)
}
Loading…
Cancel
Save