app password: add tests for the rest routes

This commit is contained in:
Girish Ramakrishnan
2020-02-01 10:00:52 -08:00
parent a5f35f39fe
commit a84cdc3d09
2 changed files with 73 additions and 2 deletions

View File

@@ -728,5 +728,75 @@ describe('Users API', function () {
done();
});
});
it('cannot add app password with invalid token', function (done) {
superagent.post(SERVER_URL + '/api/v1/app_passwords')
.query({ access_token: token + 'xx' })
.send({ name: 'my-device', identifier: 'someapp' })
.end(function (error, result) {
expect(result.statusCode).to.equal(401);
done();
});
});
it('cannot add app password without name', function (done) {
superagent.post(SERVER_URL + '/api/v1/app_passwords')
.query({ access_token: token })
.send({ identifier: 'someapp' })
.end(function (error, result) {
expect(result.statusCode).to.equal(400);
done();
});
});
let pwd;
it('can add app password', function (done) {
superagent.post(SERVER_URL + '/api/v1/app_passwords')
.query({ access_token: token })
.send({ name: 'my-device', identifier: 'someapp' })
.end(function (error, result) {
expect(result.statusCode).to.equal(201);
expect(result.body.password).to.be.a('string');
pwd = result.body;
done();
});
});
it('can get app passwords', function (done) {
superagent.get(SERVER_URL + '/api/v1/app_passwords')
.query({ access_token: token })
.end(function (error, result) {
expect(result.statusCode).to.equal(200);
expect(result.body.appPasswords).to.be.an(Array);
expect(result.body.appPasswords.length).to.be(1);
expect(result.body.appPasswords[0].name).to.be('my-device');
expect(result.body.appPasswords[0].identifier).to.be('someapp');
expect(result.body.appPasswords[0].hashedPassword).to.be(undefined);
expect(result.body.appPasswords[0].password).to.be(undefined);
done();
});
});
it('can get app password', function (done) {
superagent.get(SERVER_URL + '/api/v1/app_passwords/' + pwd.id)
.query({ access_token: token })
.end(function (error, result) {
expect(result.statusCode).to.equal(200);
expect(result.body.name).to.be('my-device');
expect(result.body.identifier).to.be('someapp');
expect(result.body.hashedPassword).to.be(undefined);
expect(result.body.password).to.be(undefined);
done();
});
});
it('can del app password', function (done) {
superagent.del(SERVER_URL + '/api/v1/app_passwords/' + pwd.id)
.query({ access_token: token })
.end(function (error, result) {
expect(result.statusCode).to.equal(204);
done();
});
});
});