test: fix appstore test

This commit is contained in:
Girish Ramakrishnan
2025-06-06 11:09:48 +02:00
parent c49050ea69
commit 2b52e21ccf
2 changed files with 1 additions and 96 deletions
-95
View File
@@ -17,7 +17,6 @@ const { setup, cleanup, serverUrl, owner, appstoreToken } = common;
describe('Appstore Apps API', function () {
before(setup);
before(() => { if (!nock.isActive()) nock.activate(); });
after(cleanup);
it('cannot list apps when appstore is down', async function () {
@@ -76,97 +75,3 @@ describe('Appstore Apps API', function () {
expect(scope1.isDone()).to.be.ok();
});
});
describe('Appstore Cloudron Registration API - existing user', function () {
before(async function () {
await setup();
await appstore._unregister();
});
after(cleanup);
it('can setup subscription', async function () {
const scope1 = nock(await appstore.getApiServerOrigin())
.post('/api/v1/register_user', (body) => body.email && body.password && body.utmSource)
.reply(201, {});
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(await appstore.getApiServerOrigin())
.post('/api/v1/register_cloudron', (body) => typeof body.domain === 'string' && typeof body.version === 'string')
.reply(201, { cloudronId: 'cid', cloudronToken: 'CLOUDRON_TOKEN' });
const response = await superagent.post(`${serverUrl}/api/v1/appstore/register_cloudron`)
.send({ email: 'test@cloudron.io', password: 'secret', signup: false })
.query({ access_token: owner.token })
.ok(() => true);
expect(response.status).to.equal(201);
expect(scope1.isDone()).to.not.be.ok(); // should not have called register_user since signup is false
expect(scope2.isDone()).to.be.ok();
expect(scope3.isDone()).to.be.ok();
expect(await settings.get(settings.APPSTORE_API_TOKEN_KEY)).to.be('CLOUDRON_TOKEN');
nock.cleanAll();
});
it('can get subscription', async function () {
const scope1 = nock(await appstore.getApiServerOrigin())
.get('/api/v1/subscription?accessToken=CLOUDRON_TOKEN', () => true)
.reply(200, { subscription: { plan: { id: 'free' } }, email: 'test@cloudron.io' });
const response = await superagent.get(`${serverUrl}/api/v1/appstore/subscription`)
.query({ access_token: owner.token });
expect(response.status).to.equal(200);
expect(response.body.email).to.be('test@cloudron.io');
expect(response.body.subscription).to.be.an('object');
expect(scope1.isDone()).to.be.ok();
});
});
describe('Appstore Cloudron Registration API - new user signup', function () {
before(async function () {
await setup();
await appstore._unregister();
});
after(cleanup);
it('can setup subscription', async function () {
const scope1 = nock(await appstore.getApiServerOrigin())
.post('/api/v1/register_user', (body) => body.email && body.password && body.utmSource)
.reply(201, {});
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(await appstore.getApiServerOrigin())
.post('/api/v1/register_cloudron', (body) => !!body.domain && body.accessToken === 'SECRET_TOKEN')
.reply(201, { cloudronId: 'cid', cloudronToken: 'CLOUDRON_TOKEN' });
const response = await superagent.post(`${serverUrl}/api/v1/appstore/register_cloudron`)
.send({ email: 'test@cloudron.io', password: 'secret', signup: true })
.query({ access_token: owner.token });
expect(response.status).to.equal(201);
expect(scope1.isDone()).to.be.ok();
expect(scope2.isDone()).to.be.ok();
expect(scope3.isDone()).to.be.ok();
expect(await settings.get(settings.APPSTORE_API_TOKEN_KEY)).to.be('CLOUDRON_TOKEN');
});
it('can get subscription', async function () {
const scope1 = nock(await appstore.getApiServerOrigin())
.get('/api/v1/subscription?accessToken=CLOUDRON_TOKEN', () => true)
.reply(200, { subscription: { plan: { id: 'free' } }, email: 'test@cloudron.io' });
const response = await superagent.get(`${serverUrl}/api/v1/appstore/subscription`)
.query({ access_token: owner.token });
expect(response.status).to.equal(200);
expect(response.body.email).to.be('test@cloudron.io');
expect(response.body.subscription).to.be.an('object');
expect(scope1.isDone()).to.be.ok();
});
});
+1 -1
View File
@@ -138,7 +138,7 @@ async function setup() {
// create owner
const scope1 = nock(await appstore.getApiServerOrigin())
.post('/api/v1/register_cloudron3', (body) => typeof body.domain === 'string' && typeof body.version === 'string')
.reply(201, { id: 'cid', token: 'CLOUDRON_TOKEN' });
.reply(201, { cloudronId: 'cid', cloudronToken: 'CLOUDRON_TOKEN' });
response = await superagent.post(`${serverUrl}/api/v1/provision/activate`)
.query({ setupToken: 'somesetuptoken' })
.send({ username: owner.username, password: owner.password, email: owner.email });