Skip to content

Commit

Permalink
Tests: superagent supports promises
Browse files Browse the repository at this point in the history
  • Loading branch information
campersau committed Oct 3, 2024
1 parent edff144 commit 8d5ae31
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 39 deletions.
28 changes: 12 additions & 16 deletions test/spec.git-api.conflict.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,16 +59,15 @@ describe('git-api conflict rebase', function () {
});
});

it('should be possible to rebase on master', (done) => {
req
it('should be possible to rebase on master', () => {
return req
.post(`${restGit.pathPrefix}/rebase`)
.send({ path: testDir, onto: 'master' })
.set('Accept', 'application/json')
.expect('Content-Type', /json/)
.expect(400)
.end((err, res) => {
.then((res) => {
expect(res.body.errorCode).to.be('merge-failed');
done();
});
});

Expand Down Expand Up @@ -141,16 +140,15 @@ describe('git-api conflict checkout', function () {
return common.post(req, '/testing/changefile', { file: path.join(testDir, testFile1) });
});

it('should be possible to checkout with local files that will conflict', (done) => {
req
it('should be possible to checkout with local files that will conflict', () => {
return req
.post(`${restGit.pathPrefix}/checkout`)
.send({ path: testDir, name: testBranch })
.set('Accept', 'application/json')
.expect('Content-Type', /json/)
.expect(400)
.end((err, res) => {
.then((res) => {
expect(res.body.errorCode).to.be('merge-failed');
done();
});
});

Expand Down Expand Up @@ -218,16 +216,15 @@ describe('git-api conflict merge', function () {
});
});

it('should be possible to merge the branches', (done) => {
req
it('should be possible to merge the branches', () => {
return req
.post(`${restGit.pathPrefix}/merge`)
.send({ path: testDir, with: 'master' })
.set('Accept', 'application/json')
.expect('Content-Type', /json/)
.expect(400)
.end((err, res) => {
.then((res) => {
expect(res.body.errorCode).to.be('merge-failed');
done();
});
});

Expand Down Expand Up @@ -328,16 +325,15 @@ describe('git-api conflict solve by deleting', function () {
});
});

it('should be possible to rebase on master', (done) => {
req
it('should be possible to rebase on master', () => {
return req
.post(`${restGit.pathPrefix}/rebase`)
.send({ path: testDir, onto: 'master' })
.set('Accept', 'application/json')
.expect('Content-Type', /json/)
.expect(400)
.end((err, res) => {
.then((res) => {
expect(res.body.errorCode).to.be('merge-failed');
done();
});
});

Expand Down
40 changes: 17 additions & 23 deletions test/spec.git-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,15 @@ describe('git-api', () => {
});
});

it('status should fail in uninited directory', (done) => {
req
it('status should fail in uninited directory', () => {
return req
.get(`${restGit.pathPrefix}/status`)
.query({ path: path.join(testDir, 'nowhere') })
.set('Accept', 'application/json')
.expect('Content-Type', /json/)
.expect(400)
.end((err, res) => {
.then((res) => {
expect(res.body.errorCode).to.be('no-such-path');
done();
});
});

Expand Down Expand Up @@ -125,14 +124,13 @@ describe('git-api', () => {
.then((res) => expect(res).to.eql({ type: 'inited', gitRootPath: testDir }));
});

it("commit should fail on when there's no files to commit", (done) => {
req
it("commit should fail on when there's no files to commit", () => {
return req
.post(`${restGit.pathPrefix}/commit`)
.send({ path: testDir, message: 'test', files: [] })
.set('Accept', 'application/json')
.expect('Content-Type', /json/)
.expect(400)
.end(done);
.expect(400);
});

// testFile
Expand All @@ -151,14 +149,13 @@ describe('git-api', () => {
});
});

it('commit should fail on non-existing file', (done) => {
req
it('commit should fail on non-existing file', () => {
return req
.post(`${restGit.pathPrefix}/commit`)
.send({ path: testDir, message: 'test', files: [{ name: testFile }] })
.set('Accept', 'application/json')
.expect('Content-Type', /json/)
.expect(400)
.end(done);
.expect(400);
});

it('creating test file should work', () => {
Expand Down Expand Up @@ -186,14 +183,13 @@ describe('git-api', () => {

// commitMessage

it('commit should fail without commit message', (done) => {
req
it('commit should fail without commit message', () => {
return req
.post(`${restGit.pathPrefix}/commit`)
.send({ path: testDir, message: undefined, files: [{ name: testFile }] })
.set('Accept', 'application/json')
.expect('Content-Type', /json/)
.expect(400)
.end(done);
.expect(400);
});

it("commit should succeed when there's files to commit", () => {
Expand Down Expand Up @@ -295,14 +291,13 @@ describe('git-api', () => {
});
});

it('discarding the new file should work', (done) => {
req
it('discarding the new file should work', () => {
return req
.post(`${restGit.pathPrefix}/discardchanges`)
.send({ path: testDir, file: testFile2 })
.set('Accept', 'application/json')
.expect('Content-Type', /json/)
.expect(200)
.end(done);
.expect(200);
});

// testSubDir
Expand Down Expand Up @@ -443,14 +438,13 @@ describe('git-api', () => {
});
});

it('get the baserepopath without base repo should work', (done) => {
it('get the baserepopath without base repo should work', () => {
const baseRepoPathTestDir = path.join(testDir, 'depth1', 'depth2');

mkdirp(baseRepoPathTestDir).then(() => {
return mkdirp(baseRepoPathTestDir).then(() => {
return common.get(req, '/baserepopath', { path: baseRepoPathTestDir }).then((res) => {
// Some oses uses symlink and path will be different as git will return resolved symlink
expect(res.path).to.contain(testDir);
done();
});
});
});
Expand Down

0 comments on commit 8d5ae31

Please sign in to comment.