mirror of https://github.com/nocodb/nocodb
Muhammed Mustafa
2 years ago
4 changed files with 88 additions and 3 deletions
@ -0,0 +1,17 @@
|
||||
import request from 'supertest'; |
||||
|
||||
const defaultProjectValue = { |
||||
title: 'Title', |
||||
}; |
||||
|
||||
const createProject = async (app, token) => { |
||||
const response = await request(app) |
||||
.post('/api/v1/db/meta/projects/') |
||||
.set('xc-auth', token) |
||||
.send(defaultProjectValue); |
||||
|
||||
const project = response.body; |
||||
return project; |
||||
}; |
||||
|
||||
export { createProject }; |
@ -1,10 +1,16 @@
|
||||
import request from 'supertest'; |
||||
import User from '../../../../../lib/models/User'; |
||||
|
||||
const createUser = async (app, email, password) => { |
||||
const createUser = async ( |
||||
app, |
||||
email = 'test@example.com', |
||||
password = 'A1234abh2@dsad' |
||||
) => { |
||||
const response = await request(app) |
||||
.post('/api/v1/auth/user/signup') |
||||
.send({ email, password }); |
||||
return { token: response.body.token }; |
||||
const user = User.getByEmail(email); |
||||
return { token: response.body.token, user }; |
||||
}; |
||||
|
||||
export { createUser }; |
||||
|
@ -0,0 +1,60 @@
|
||||
import 'mocha'; |
||||
import request from 'supertest'; |
||||
import server from '../server'; |
||||
import Project from '../../../../lib/models/Project'; |
||||
import { createProject } from './helpers/project'; |
||||
import { createUser } from './helpers/user'; |
||||
|
||||
function projectTest() { |
||||
let app; |
||||
let token; |
||||
let project; |
||||
|
||||
before(async function () { |
||||
app = await server(); |
||||
const response = await createUser(app); |
||||
token = response.token; |
||||
project = await createProject(app, token); |
||||
}); |
||||
|
||||
it('List projects', function (done) { |
||||
request(app) |
||||
.get('/api/v1/db/meta/projects/') |
||||
.set('xc-auth', token) |
||||
.send({}) |
||||
.expect(200, (err, res) => { |
||||
if (err) done(err); |
||||
else if (res.body.list.length !== 1) done('Should list only 1 project'); |
||||
else { |
||||
done(); |
||||
} |
||||
}); |
||||
}); |
||||
|
||||
it('Update projects', function (done) { |
||||
request(app) |
||||
.patch(`/api/v1/db/meta/projects/${project.id}`) |
||||
.set('xc-auth', token) |
||||
.send({ |
||||
title: 'NewTitle', |
||||
}) |
||||
.expect(200, async (err) => { |
||||
if (err) { |
||||
done(err); |
||||
return; |
||||
} |
||||
const newProject = await Project.getByTitleOrId(project.id); |
||||
console.log(newProject); |
||||
if (newProject.title !== 'NewTitle') { |
||||
done('Project not updated'); |
||||
return; |
||||
} |
||||
|
||||
done(); |
||||
}); |
||||
}); |
||||
} |
||||
|
||||
export default function () { |
||||
describe('Project', projectTest); |
||||
} |
Loading…
Reference in new issue