move appstore urls into appstore.js
This commit is contained in:
@@ -67,6 +67,7 @@ exports = module.exports = {
|
||||
};
|
||||
|
||||
const apps = require('../apps.js'),
|
||||
appstore = require('../appstore.js'),
|
||||
assert = require('assert'),
|
||||
AuditSource = require('../auditsource.js'),
|
||||
BoxError = require('../boxerror.js'),
|
||||
@@ -180,7 +181,7 @@ async function install(req, res, next) {
|
||||
|
||||
if ('enableTurn' in data && typeof data.enableTurn !== 'boolean') return next(new HttpError(400, 'enableTurn must be boolean'));
|
||||
|
||||
let [error, result] = await safe(apps.downloadManifest(data.appStoreId, data.manifest));
|
||||
let [error, result] = await safe(appstore.downloadManifest(data.appStoreId, data.manifest));
|
||||
if (error) return next(BoxError.toHttpError(error));
|
||||
|
||||
if (result.appStoreId === constants.PROXY_APP_APPSTORE_ID && typeof data.upstreamUri !== 'string') return next(new HttpError(400, 'upstreamUri must be a non empty string'));
|
||||
|
||||
@@ -27,7 +27,7 @@ describe('Appstore Apps API', function () {
|
||||
});
|
||||
|
||||
it('cannot get app with bad token', async function () {
|
||||
const scope1 = nock(settings.apiServerOrigin())
|
||||
const scope1 = nock(await appstore.getApiServerOrigin())
|
||||
.get(`/api/v1/apps/org.wordpress.cloudronapp?accessToken=${appstoreToken}`)
|
||||
.reply(403, {});
|
||||
|
||||
@@ -40,7 +40,7 @@ describe('Appstore Apps API', function () {
|
||||
});
|
||||
|
||||
it('can list apps', async function () {
|
||||
const scope1 = nock(settings.apiServerOrigin())
|
||||
const scope1 = nock(await appstore.getApiServerOrigin())
|
||||
.get(`/api/v1/apps?accessToken=${appstoreToken}&boxVersion=${constants.VERSION}&unstable=true`, () => true)
|
||||
.reply(200, { apps: [] });
|
||||
|
||||
@@ -52,7 +52,7 @@ describe('Appstore Apps API', function () {
|
||||
});
|
||||
|
||||
it('can get app', async function () {
|
||||
const scope1 = nock(settings.apiServerOrigin())
|
||||
const scope1 = nock(await appstore.getApiServerOrigin())
|
||||
.get(`/api/v1/apps/org.wordpress.cloudronapp?accessToken=${appstoreToken}`, () => true)
|
||||
.reply(200, { apps: [] });
|
||||
|
||||
@@ -64,7 +64,7 @@ describe('Appstore Apps API', function () {
|
||||
});
|
||||
|
||||
it('can get app version', async function () {
|
||||
const scope1 = nock(settings.apiServerOrigin())
|
||||
const scope1 = nock(await appstore.getApiServerOrigin())
|
||||
.get(`/api/v1/apps/org.wordpress.cloudronapp/versions/3.4.2?accessToken=${appstoreToken}`, () => true)
|
||||
.reply(200, { apps: [] });
|
||||
|
||||
@@ -84,15 +84,15 @@ describe('Appstore Cloudron Registration API - existing user', function () {
|
||||
after(cleanup);
|
||||
|
||||
it('can setup subscription', async function () {
|
||||
const scope1 = nock(settings.apiServerOrigin())
|
||||
const scope1 = nock(await appstore.getApiServerOrigin())
|
||||
.post('/api/v1/register_user', (body) => body.email && body.password && body.utmSource)
|
||||
.reply(201, {});
|
||||
|
||||
const scope2 = nock(settings.apiServerOrigin())
|
||||
const scope2 = nock(await appstore.getApiServerOrigin())
|
||||
.post('/api/v1/login', (body) => body.email && body.password)
|
||||
.reply(200, { userId: 'userId', accessToken: 'SECRET_TOKEN' });
|
||||
|
||||
const scope3 = nock(settings.apiServerOrigin())
|
||||
const scope3 = nock(await appstore.getApiServerOrigin())
|
||||
.post('/api/v1/register_cloudron', (body) => !!body.domain && body.accessToken === 'SECRET_TOKEN')
|
||||
.reply(201, { cloudronId: 'cid', cloudronToken: 'CLOUDRON_TOKEN' });
|
||||
|
||||
@@ -111,7 +111,7 @@ describe('Appstore Cloudron Registration API - existing user', function () {
|
||||
});
|
||||
|
||||
it('can get subscription', async function () {
|
||||
const scope1 = nock(settings.apiServerOrigin())
|
||||
const scope1 = nock(await appstore.getApiServerOrigin())
|
||||
.get('/api/v1/subscription?accessToken=CLOUDRON_TOKEN', () => true)
|
||||
.reply(200, { subscription: { plan: { id: 'free' } }, email: 'test@cloudron.io' });
|
||||
|
||||
@@ -133,15 +133,15 @@ describe('Appstore Cloudron Registration API - new user signup', function () {
|
||||
after(cleanup);
|
||||
|
||||
it('can setup subscription', async function () {
|
||||
const scope1 = nock(settings.apiServerOrigin())
|
||||
const scope1 = nock(await appstore.getApiServerOrigin())
|
||||
.post('/api/v1/register_user', (body) => body.email && body.password && body.utmSource)
|
||||
.reply(201, {});
|
||||
|
||||
const scope2 = nock(settings.apiServerOrigin())
|
||||
const scope2 = nock(await appstore.getApiServerOrigin())
|
||||
.post('/api/v1/login', (body) => body.email && body.password)
|
||||
.reply(200, { userId: 'userId', accessToken: 'SECRET_TOKEN' });
|
||||
|
||||
const scope3 = nock(settings.apiServerOrigin())
|
||||
const scope3 = nock(await appstore.getApiServerOrigin())
|
||||
.post('/api/v1/register_cloudron', (body) => !!body.domain && body.accessToken === 'SECRET_TOKEN')
|
||||
.reply(201, { cloudronId: 'cid', cloudronToken: 'CLOUDRON_TOKEN' });
|
||||
|
||||
@@ -158,7 +158,7 @@ describe('Appstore Cloudron Registration API - new user signup', function () {
|
||||
});
|
||||
|
||||
it('can get subscription', async function () {
|
||||
const scope1 = nock(settings.apiServerOrigin())
|
||||
const scope1 = nock(await appstore.getApiServerOrigin())
|
||||
.get('/api/v1/subscription?accessToken=CLOUDRON_TOKEN', () => true)
|
||||
.reply(200, { subscription: { plan: { id: 'free' } }, email: 'test@cloudron.io' });
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
'use strict';
|
||||
|
||||
const constants = require('../../constants.js'),
|
||||
const appstore = require('../../appstore.js'),
|
||||
constants = require('../../constants.js'),
|
||||
database = require('../../database.js'),
|
||||
expect = require('expect.js'),
|
||||
fs = require('fs'),
|
||||
@@ -60,7 +61,7 @@ async function setupServer() {
|
||||
await database._clear();
|
||||
await oidc.stop();
|
||||
await database.initialize();
|
||||
await settings._setApiServerOrigin(exports.mockApiServerOrigin);
|
||||
await appstore._setApiServerOrigin(exports.mockApiServerOrigin);
|
||||
await server.start();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user