Skip to content

Commit

Permalink
endpoints/getting-started tests to mocha (#1248)
Browse files Browse the repository at this point in the history
  • Loading branch information
AVaksman authored and fhinkel committed Apr 12, 2019
1 parent 797b31e commit 247eb82
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 20 deletions.
4 changes: 2 additions & 2 deletions endpoints/getting-started/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
},
"scripts": {
"start": "node app.js",
"test": "repo-tools test run --cmd ava -- -T 20s --verbose test/*.test.js"
"test": "repo-tools test run --cmd mocha -- test/*.test.js --timeout=20000"
},
"dependencies": {
"body-parser": "^1.18.3",
Expand All @@ -23,7 +23,7 @@
},
"devDependencies": {
"@google-cloud/nodejs-repo-tools": "^3.0.0",
"ava": "^0.25.0",
"mocha": "^6.0.0",
"proxyquire": "^2.1.0",
"sinon": "^7.2.7",
"supertest": "^4.0.0"
Expand Down
33 changes: 15 additions & 18 deletions endpoints/getting-started/test/app.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const path = require('path');
const proxyquire = require('proxyquire').noPreserveCache();
const request = require('supertest');
const sinon = require('sinon');
const test = require('ava');
const assert = require('assert');
const tools = require('@google-cloud/nodejs-repo-tools');

const SAMPLE_PATH = path.join(__dirname, '../app.js');
Expand All @@ -42,40 +42,37 @@ function getSample() {
};
}

test.beforeEach(tools.stubConsole);
test.afterEach.always(tools.restoreConsole);
beforeEach(tools.stubConsole);
afterEach(tools.restoreConsole);

test.cb('should echo a message', t => {
request(getSample().app)
it('should echo a message', async () => {
await request(getSample().app)
.post('/echo')
.send({message: 'foo'})
.expect(200)
.expect(response => {
t.is(response.body.message, 'foo');
})
.end(t.end);
assert.strictEqual(response.body.message, 'foo');
});
});

test.cb('should try to parse encoded info', t => {
request(getSample().app)
it('should try to parse encoded info', async () => {
await request(getSample().app)
.get('/auth/info/googlejwt')
.expect(200)
.expect(response => {
t.deepEqual(response.body, {id: 'anonymous'});
})
.end(t.end);
assert.deepStrictEqual(response.body, {id: 'anonymous'});
});
});

test.cb('should successfully parse encoded info', t => {
request(getSample().app)
it('should successfully parse encoded info', async () => {
await request(getSample().app)
.get('/auth/info/googlejwt')
.set(
'X-Endpoint-API-UserInfo',
Buffer.from(JSON.stringify({id: 'foo'})).toString('base64')
)
.expect(200)
.expect(response => {
t.deepEqual(response.body, {id: 'foo'});
})
.end(t.end);
assert.deepStrictEqual(response.body, {id: 'foo'});
});
});

0 comments on commit 247eb82

Please sign in to comment.