Skip to content

Commit

Permalink
test: update test api calls with /api
Browse files Browse the repository at this point in the history
  • Loading branch information
JamieSlome committed Feb 21, 2024
1 parent f8f6a72 commit c3bb9ba
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 15 deletions.
2 changes: 1 addition & 1 deletion test/1.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ describe('init', async () => {
});

it('should not be logged in', async function () {
const res = await chai.request(app).get('/auth/profile');
const res = await chai.request(app).get('/api/auth/profile');

res.should.have.status(401);
});
Expand Down
16 changes: 15 additions & 1 deletion test/addRepoTest.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ describe('add new repo', async () => {
});

it('login', async function () {
const res = await chai.request(app).post('/auth/login').send({
const res = await chai.request(app).post('/api/auth/login').send({
username: 'admin',
password: 'admin',
});
Expand Down Expand Up @@ -168,6 +168,20 @@ describe('add new repo', async () => {
repo.users.canAuthorise.length.should.equal(1);
});

it('Valid user push permission on repo', async function () {
const res = (await chai.request(app).patch('/api/v1/repo/test-repo/user/authorise'))
.setEncoding('Cookie', `${cookie}`)
.send({ username: 'u2' });
res.should.have.status(200);
const isAllowed = await db.isUserPushAllowed('test-repo', 'u2');
expect(isAllowed).to.be.true;
});

it('Invalid user push permission on repo', async function () {
const isAllowed = await db.isUserPushAllowed('test-repo', 'test');
expect(isAllowed).to.be.false;
});

after(async function () {
await service.httpServer.close();
});
Expand Down
10 changes: 5 additions & 5 deletions test/testLogin.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ describe('auth', async () => {
describe('test login / logout', async function () {
// Test to get all students record
it('should get 401 not logged in', async function () {
const res = await chai.request(app).get('/auth/profile');
const res = await chai.request(app).get('/api/auth/profile');

res.should.have.status(401);
});

it('should be able to login', async function () {
const res = await chai.request(app).post('/auth/login').send({
const res = await chai.request(app).post('/api/auth/login').send({
username: 'admin',
password: 'admin',
});
Expand All @@ -43,17 +43,17 @@ describe('auth', async () => {
});

it('should now be able to access the profile', async function () {
const res = await chai.request(app).get('/auth/profile').set('Cookie', `${cookie}`);
const res = await chai.request(app).get('/api/auth/profile').set('Cookie', `${cookie}`);
res.should.have.status(200);
});

it('should now be able to logout', async function () {
const res = await chai.request(app).post('/auth/logout').set('Cookie', `${cookie}`);
const res = await chai.request(app).post('/api/auth/logout').set('Cookie', `${cookie}`);
res.should.have.status(200);
});

it('test cannot access profile page', async function () {
const res = await chai.request(app).get('/auth/profile').set('Cookie', `${cookie}`);
const res = await chai.request(app).get('/api/auth/profile').set('Cookie', `${cookie}`);

res.should.have.status(401);
});
Expand Down
16 changes: 8 additions & 8 deletions test/testUserCreation.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ describe('user creation', async () => {
});

it('should be able to login', async function () {
const res = await chai.request(app).post('/auth/login').send({
const res = await chai.request(app).post('/api/auth/login').send({
username: 'admin',
password: 'admin',
});
Expand All @@ -40,7 +40,7 @@ describe('user creation', async () => {
});

it('should be able to create a new user', async function () {
const res = await chai.request(app).post('/auth/profile').set('Cookie', `${cookie}`).send({
const res = await chai.request(app).post('/api/auth/profile').set('Cookie', `${cookie}`).send({
username: 'login-test-user',
email: 'paul.timothy.groves@gmail.com',
gitAccount: 'test123',
Expand All @@ -55,7 +55,7 @@ describe('user creation', async () => {
});

it('logout', async function () {
const res = await chai.request(app).post('/auth/logout').set('Cookie', `${cookie}`);
const res = await chai.request(app).post('/api/auth/logout').set('Cookie', `${cookie}`);
res.should.have.status(200);
});

Expand All @@ -66,7 +66,7 @@ describe('user creation', async () => {
user.password = passwordHash.generate('test1234');
await db.updateUser(user);

const res = await chai.request(app).post('/auth/login').send({
const res = await chai.request(app).post('/api/auth/login').send({
username: 'login-test-user',
password: 'test1234',
});
Expand All @@ -77,7 +77,7 @@ describe('user creation', async () => {
});

it('change the password', async function () {
const res = await chai.request(app).post('/auth/password').set('Cookie', `${cookie}`).send({
const res = await chai.request(app).post('/api/auth/password').set('Cookie', `${cookie}`).send({
oldPassword: 'test1234',
newPassword: 'testabcd',
});
Expand All @@ -93,15 +93,15 @@ describe('user creation', async () => {
it('logout - again', function (done) {
chai
.request(app)
.post('/auth/logout')
.post('/api/auth/logout')
.end((err, res) => {
res.should.have.status(200);
done();
});
});

it('login again', async function () {
const res = await chai.request(app).post('/auth/login').send({
const res = await chai.request(app).post('/api/auth/login').send({
username: 'login-test-user',
password: 'testabcd',
});
Expand All @@ -112,7 +112,7 @@ describe('user creation', async () => {
});

it('should access the profile', async function () {
const res = await chai.request(app).get('/auth/profile').set('Cookie', `${cookie}`);
const res = await chai.request(app).get('/api/auth/profile').set('Cookie', `${cookie}`);
res.should.have.status(200);

res.body.username.should.equal('login-test-user');
Expand Down

0 comments on commit c3bb9ba

Please sign in to comment.