Files
cloudron-box/src/test/appstore-test.js
Girish Ramakrishnan 8da4eaf4a3 fix tests
2021-06-03 16:08:39 -07:00

80 lines
2.7 KiB
JavaScript

/* jslint node:true */
/* global it:false */
/* global describe:false */
/* global before:false */
/* global after:false */
/* global beforeEach:false */
'use strict';
const appstore = require('../appstore.js'),
common = require('./common.js'),
expect = require('expect.js'),
nock = require('nock'),
settings = require('../settings.js'),
settingsdb = require('../settingsdb.js');
const APPSTORE_TOKEN = 'appstoretoken';
const APP_ID = 'appid';
const APPSTORE_APP_ID = 'appstoreappid';
describe('Appstore', function () {
before(common.setup);
after(common.cleanup);
beforeEach(nock.cleanAll);
it('can set cloudron token', function (done) {
settingsdb.set(settings.CLOUDRON_TOKEN_KEY, APPSTORE_TOKEN, done);
});
it('can purchase an app', function (done) {
var scope1 = nock(common.MOCK_API_SERVER_ORIGIN)
.post(`/api/v1/cloudronapps?accessToken=${APPSTORE_TOKEN}`, function () { return true; })
.reply(201, {});
appstore.purchaseApp({ appId: APP_ID, appstoreId: APPSTORE_APP_ID, manifestId: APPSTORE_APP_ID }, function (error) {
expect(error).to.not.be.ok();
expect(scope1.isDone()).to.be.ok();
done();
});
});
it('unpurchase succeeds if app was never purchased', function (done) {
var scope1 = nock(common.MOCK_API_SERVER_ORIGIN)
.get(`/api/v1/cloudronapps/${APP_ID}?accessToken=${APPSTORE_TOKEN}`)
.reply(404, {});
var scope2 = nock(common.MOCK_API_SERVER_ORIGIN)
.delete(`/api/v1/cloudronapps/${APP_ID}?accessToken=${APPSTORE_TOKEN}`, function () { return true; })
.reply(204, {});
appstore.unpurchaseApp(APP_ID, { appstoreId: APPSTORE_APP_ID, manifestId: APPSTORE_APP_ID }, function (error) {
expect(error).to.not.be.ok();
expect(scope1.isDone()).to.be.ok();
expect(scope2.isDone()).to.not.be.ok();
done();
});
});
it('can unpurchase an app', function (done) {
var scope1 = nock(common.MOCK_API_SERVER_ORIGIN)
.get(`/api/v1/cloudronapps/${APP_ID}?accessToken=${APPSTORE_TOKEN}`)
.reply(200, {});
var scope2 = nock(common.MOCK_API_SERVER_ORIGIN)
.delete(`/api/v1/cloudronapps/${APP_ID}?accessToken=${APPSTORE_TOKEN}`, function () { return true; })
.reply(204, {});
appstore.unpurchaseApp(APP_ID, { appstoreId: APPSTORE_APP_ID, manifestId: APPSTORE_APP_ID }, function (error) {
expect(error).to.not.be.ok();
expect(scope1.isDone()).to.be.ok();
expect(scope2.isDone()).to.be.ok();
done();
});
});
});