add archives api
This commit is contained in:
81
src/routes/test/archives-test.js
Normal file
81
src/routes/test/archives-test.js
Normal file
@@ -0,0 +1,81 @@
|
||||
/* global it:false */
|
||||
/* global describe:false */
|
||||
/* global before:false */
|
||||
/* global after:false */
|
||||
|
||||
'use strict';
|
||||
|
||||
const backups = require('../../backups.js'),
|
||||
common = require('./common.js'),
|
||||
expect = require('expect.js'),
|
||||
superagent = require('superagent');
|
||||
|
||||
describe('Archives API', function () {
|
||||
const { setup, cleanup, serverUrl, owner } = common;
|
||||
|
||||
const nonArchiveBackup = {
|
||||
id: null,
|
||||
remotePath: 'app_appid_123',
|
||||
encryptionVersion: null,
|
||||
packageVersion: '1.0.0',
|
||||
type: backups.BACKUP_TYPE_APP,
|
||||
state: backups.BACKUP_STATE_CREATING,
|
||||
identifier: 'appid',
|
||||
dependsOn: [ ],
|
||||
manifest: { foo: 'bar' },
|
||||
format: 'tgz',
|
||||
preserveSecs: 0,
|
||||
label: '',
|
||||
archive: false
|
||||
};
|
||||
|
||||
const archiveBackup = Object.assign({}, nonArchiveBackup, {archive: true, remotePath: 'app_appid_234'});
|
||||
|
||||
before(async function () {
|
||||
await setup();
|
||||
nonArchiveBackup.id = await backups.add(nonArchiveBackup);
|
||||
archiveBackup.id = await backups.add(archiveBackup);
|
||||
await backups.update(archiveBackup.id, { archive: true });
|
||||
});
|
||||
after(cleanup);
|
||||
|
||||
it('list succeeds', async function () {
|
||||
const response = await superagent.get(`${serverUrl}/api/v1/archives`)
|
||||
.query({ access_token: owner.token });
|
||||
expect(response.statusCode).to.equal(200);
|
||||
expect(response.body.archives.length).to.be(1);
|
||||
expect(response.body.archives[0].id).to.be(archiveBackup.id);
|
||||
});
|
||||
|
||||
it('get valid archive', async function () {
|
||||
const response = await superagent.get(`${serverUrl}/api/v1/archives/${archiveBackup.id}`)
|
||||
.query({ access_token: owner.token });
|
||||
expect(response.statusCode).to.equal(200);
|
||||
expect(response.body.remotePath).to.be('app_appid_234');
|
||||
});
|
||||
|
||||
it('cannot get invalid archive', async function () {
|
||||
const response = await superagent.get(`${serverUrl}/api/v1/archives/random`)
|
||||
.query({ access_token: owner.token })
|
||||
.ok(() => true);
|
||||
expect(response.statusCode).to.equal(404);
|
||||
});
|
||||
|
||||
it('cannot del invalid archive', async function () {
|
||||
const response = await superagent.del(`${serverUrl}/api/v1/archives/${nonArchiveBackup.id}`)
|
||||
.query({ access_token: owner.token })
|
||||
.ok(() => true);
|
||||
expect(response.statusCode).to.equal(404);
|
||||
});
|
||||
|
||||
it('del valid archive', async function () {
|
||||
const response = await superagent.del(`${serverUrl}/api/v1/archives/${archiveBackup.id}`)
|
||||
.query({ access_token: owner.token });
|
||||
expect(response.statusCode).to.equal(204);
|
||||
|
||||
const response2 = await superagent.get(`${serverUrl}/api/v1/archives`)
|
||||
.query({ access_token: owner.token });
|
||||
expect(response2.statusCode).to.equal(200);
|
||||
expect(response2.body.archives.length).to.be(0);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user