Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 3 additions & 14 deletions src/commands/app/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ export default class AppCreate extends Command {
const planDetails = plans.projectBundlePlans[bundlePlan];

return Object.keys(planDetails)
.filter((key) => planDetails[key].available)
.filter((key) => key !== 'free' && planDetails[key].available)
.map((key) => {
const { displayPrice } = planDetails[key];
return {
Expand Down Expand Up @@ -200,7 +200,7 @@ export default class AppCreate extends Command {
...Object.keys(plans.projects)
.filter((plan) => {
if (
(plan === 'free' || plan.includes('g2')) &&
plan.includes('g2') &&
plans.projects[plan].available &&
plans.projects[plan].region === 'iran'
) {
Expand All @@ -216,18 +216,7 @@ export default class AppCreate extends Command {
const storageClass = availablePlan.storageClass;
return {
value: plan,
name: `RAM: ${ram}${' '.repeat(
5 - ram.toString().length,
)} GB, CPU: ${cpu}${' '.repeat(
6 - cpu.toString().length,
)}Core, Disk: ${disk}${
' '.repeat(5 - disk.toString().length) + 'GB'
}${storageClass || 'SSD'}, Price: ${price.toLocaleString()}${
price
? ' '.repeat(7 - Math.floor(price).toString().length) +
'Tomans/Month'
: ''
}`,
name: `RAM: ${String(ram).padEnd(5)} GB, CPU: ${String(cpu).padEnd(6)}Core, Disk: ${String(disk).padEnd(5)}GB${storageClass || 'SSD'}, Price: ${price.toLocaleString().padEnd(10)} Tomans/Month`,
};
}),
],
Expand Down
16 changes: 4 additions & 12 deletions src/commands/db/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -260,20 +260,12 @@ export default class Create extends Command {
const disk = availablePlan.volume;
const price = availablePlan.price * 720;
const storageClass = availablePlan.storageClass;
const priceLabel = price
? `${price.toLocaleString().padEnd(10)} Tomans/Month`
: price.toLocaleString();
return {
value: plan,
name: `RAM: ${ram}${' '.repeat(
5 - ram.toString().length,
)} GB, CPU: ${cpu}${' '.repeat(
6 - cpu.toString().length,
)}Core, Disk: ${disk}${
' '.repeat(5 - disk.toString().length) + 'GB'
}${storageClass || 'SSD'}, Price: ${price.toLocaleString()}${
price
? ' '.repeat(7 - Math.floor(price).toString().length) +
'Tomans/Month'
: ''
}`,
name: `RAM: ${String(ram).padEnd(5)} GB, CPU: ${String(cpu).padEnd(6)}Core, Disk: ${String(disk).padEnd(5)}GB${storageClass || 'SSD'}, Price: ${priceLabel}`,
};
}),
],
Expand Down
5 changes: 4 additions & 1 deletion src/commands/mail/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,10 @@ export default class MailCreate extends Command {
message: 'Please select a plan:',
choices: [
...Object.keys(plans.mail)
.filter((plan) => plans.mail[plan].available)
.filter(
(plan) =>
MAIL_SERVICE_PLANS.includes(plan) && plans.mail[plan].available,
)
.map((plan) => {
const availablePlan = plans.mail[plan];
const maxAccount = availablePlan.maxAccount;
Expand Down
17 changes: 6 additions & 11 deletions src/commands/plan/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,16 @@ export default class PlanList extends Command {
const plansData = Object.keys(plans.projects)
.filter(
(plan) =>
(plan === 'free' || plan.includes('g2')) &&
plan.includes('g2') &&
plans.projects[plan].available &&
plans.projects[plan].region === 'iran',
)
.map((plan) => {
const Plan = plan;
const BundlePlan = plans.projectBundlePlans[plan];
const BundlePlanDetails = Object.keys(BundlePlan).map((key) => {
const { displayPrice } = BundlePlan[key];
return { key, displayPrice };
});

const Free = BundlePlanDetails[0].displayPrice.toLocaleString();
const Standard = BundlePlanDetails[1].displayPrice.toLocaleString();
const Pro = BundlePlanDetails[2].displayPrice.toLocaleString();
const Basic = BundlePlan.basic.displayPrice.toLocaleString();
const Standard = BundlePlan.standard.displayPrice.toLocaleString();
const Pro = BundlePlan.pro.displayPrice.toLocaleString();

const availablePlan = plans.projects[plan];
const RAM = availablePlan.RAM.amount;
Expand All @@ -50,7 +45,7 @@ export default class PlanList extends Command {
CPU,
Disk,
Price,
Free,
Basic,
Standard,
Pro,
};
Expand All @@ -64,7 +59,7 @@ export default class PlanList extends Command {
CPU: { header: 'CPU(Core)' },
Disk: { header: 'Disk(GB SSD)' },
Price: { header: 'Price(Tomans/Month)' },
Free: { header: 'Bronze' },
Basic: { header: 'Bronze(Tomans/Month)' },
Standard: { header: 'Silver(Tomans/Month)' },
Pro: { header: 'Gold(Tomans/Month)' },
},
Expand Down
38 changes: 16 additions & 22 deletions src/commands/vm/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,28 +167,22 @@ export default class VmCreate extends Command {
name: 'plan',
type: 'list',
message: 'Please select a plan:',
choices: Object.keys(plans).map((planKey) => {
const planDetails = plans[planKey];
const { RAM, CPU, volume, monthlyPrice } = planDetails;
const ram = `RAM: ${RAM.amount}${' '.repeat(
4 - RAM.amount.toString().length,
)} GB`;
const cpu = `CPU: ${CPU.amount}${' '.repeat(
4 - CPU.amount.toString().length,
)} Core${CPU.amount > 1 ? 's' : ' '}`;

const disk = `Disk: ${volume}${' '.repeat(
4 - volume.toString().length,
)} GB`;
const price = `Price: ${monthlyPrice.toLocaleString()}${' '.repeat(
10 - monthlyPrice.toLocaleString().length,
)} Tomans/Month`;

return {
value: planKey,
name: `${ram.padEnd(8)} | ${cpu.padEnd(10)} | ${disk.padEnd(8)} | ${price}`,
};
}),
choices: Object.keys(plans)
.filter((planKey) => !planKey.startsWith('free'))
.map((planKey) => {
const planDetails = plans[planKey];
const { RAM, CPU, volume, monthlyPrice } = planDetails;
const ram = `RAM: ${String(RAM.amount).padEnd(4)} GB`;
const cpu = `CPU: ${String(CPU.amount).padEnd(4)} Core${CPU.amount > 1 ? 's' : ' '}`;

const disk = `Disk: ${String(volume).padEnd(4)} GB`;
const price = `Price: ${monthlyPrice.toLocaleString().padEnd(10)} Tomans/Month`;

return {
value: planKey,
name: `${ram.padEnd(8)} | ${cpu.padEnd(10)} | ${disk.padEnd(8)} | ${price}`,
};
}),
})) as { plan: string };

return plan;
Expand Down
11 changes: 1 addition & 10 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,7 @@ export const AVAILABLE_PLATFORMS = [
];

export const OBJ_PERMISSION = ['public', 'private'];
export const MAIL_SERVICE_PLANS = [
'm1',
'm2',
'm3',
'm4',
'm5',
'm6',
'm7',
'm8',
];
export const MAIL_SERVICE_PLANS = ['m2', 'm3', 'm4', 'm5', 'm6', 'm7', 'm8'];

export const MAIL_SERVICE_MODES = ['DEV', 'LIVE'];

Expand Down
98 changes: 98 additions & 0 deletions test/app/create.unit.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { runCommand } from '@oclif/test';
import nock from 'nock';
import sinon from 'sinon';
import inquirer from 'inquirer';
import { expect } from 'chai';
import { networks } from '../fixtures/networks/fixture.ts';
import { stubGlobalConfig } from '../helpers/stubs.ts';
Expand Down Expand Up @@ -314,4 +315,101 @@ describe('app:create', function () {

expect(stdout).to.equal('App test-app created.\n');
});

it('lists a plan with an 8-digit monthly price', async () => {
api
.get('/v1/me')
.query({ teamID: '' })
.reply(200, {
plans: {
projects: {
'small-g2': {
available: true,
region: 'iran',
RAM: { amount: 8 },
CPU: { amount: 4 },
volume: 100,
price: 20000,
},
},
},
});
api
.post('/v1/projects/', {
name: 'test-app',
planID: 'small-g2',
platform: 'laravel',
bundlePlanID: 'standard',
network: networks.networks[0]._id,
readOnlyRootFilesystem: true,
})
.query({ teamID: '' })
.reply(200);
const prompt = sinon
.stub(inquirer, 'prompt')
.resolves({ plan: 'small-g2' });

const { error } = await runCommand(
createFlags.filter((flag) => flag !== '--plan' && flag !== 'small-g2'),
);

expect(error).to.equal(undefined);
expect((prompt.firstCall.args[0] as any).choices[0].name).to.include(
`${(14_400_000).toLocaleString()} Tomans/Month`,
);
});

it('does not offer the free plan or the free feature bundle', async () => {
const plan = {
available: true,
region: 'iran',
RAM: { amount: 1 },
CPU: { amount: 1 },
volume: 1,
};
api
.get('/v1/me')
.twice()
.query({ teamID: '' })
.reply(200, {
plans: {
projects: {
free: { ...plan, price: 0 },
'small-g2': { ...plan, price: 100 },
},
projectBundlePlans: {
'small-g2': {
free: { available: true, displayPrice: 0 },
standard: { available: true, displayPrice: 100 },
},
},
},
});
api
.post('/v1/projects/', {
name: 'test-app',
planID: 'small-g2',
platform: 'laravel',
bundlePlanID: 'standard',
network: networks.networks[0]._id,
readOnlyRootFilesystem: true,
})
.query({ teamID: '' })
.reply(200);
const prompt = sinon.stub(inquirer, 'prompt');
prompt.onFirstCall().resolves({ plan: 'small-g2' });
prompt.onSecondCall().resolves({ bundlePlan: 'standard' });

await runCommand(
createFlags.filter(
(flag) =>
!['--plan', 'small-g2', '--feature-plan', 'standard'].includes(flag),
),
);

const offered = (call: sinon.SinonSpyCall) =>
(call.args[0] as any).choices.map((choice: any) => choice.value);
expect(offered(prompt.firstCall)).to.deep.equal(['small-g2']);
expect(offered(prompt.secondCall)).to.deep.equal(['standard']);
});
});
32 changes: 32 additions & 0 deletions test/db/create.unit.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { runCommand } from '@oclif/test';
import nock from 'nock';
import sinon from 'sinon';
import inquirer from 'inquirer';
import { expect } from 'chai';
import { networks } from '../fixtures/networks/fixture.ts';
import { stubGlobalConfig } from '../helpers/stubs.ts';
Expand Down Expand Up @@ -130,4 +131,35 @@ describe('db:create', function () {

expect(error?.message).to.include(unableToCreate);
});

it('lists a plan with an 8-digit monthly price', async () => {
api
.get('/v1/me')
.query({ teamID: '' })
.reply(200, {
plans: {
databases: {
'small-g2': {
available: true,
supports: ['postgres'],
RAM: { amount: 8 },
CPU: { amount: 4 },
volume: 100,
price: 20000,
},
},
},
});
expectCreate().reply(200);
const prompt = sinon.stub(inquirer, 'prompt').resolves({ plan: 'small' });

const { error } = await runCommand(
flags.filter((flag) => flag !== '--plan' && flag !== 'small'),
);

expect(error).to.equal(undefined);
expect((prompt.firstCall.args[0] as any).choices[0].name).to.include(
`${(14_400_000).toLocaleString()} Tomans/Month`,
);
});
});
49 changes: 49 additions & 0 deletions test/mail/create.unit.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { runCommand } from '@oclif/test';
import nock from 'nock';
import sinon from 'sinon';
import inquirer from 'inquirer';
import { expect } from 'chai';
import { stubGlobalConfig } from '../helpers/stubs.ts';

describe('mail:create', function () {
const api = nock('https://api.liara.ir');
const mailApi = nock('https://mail-service.liara.ir');

beforeEach(() => {
nock.disableNetConnect();
stubGlobalConfig();
});

afterEach(() => {
api.done();
mailApi.done();
nock.cleanAll();
nock.enableNetConnect();
sinon.restore();
});

it('does not offer the free plan', async () => {
api
.get('/v1/me')
.query({ teamID: '' })
.reply(200, {
plans: { mail: { m1: { available: true }, m2: { available: true } } },
});
mailApi
.post('/api/v1/mails', {
domain: 'example.com',
plan: 'm2',
mode: 'DEV',
})
.query({ teamID: '' })
.reply(200);
const prompt = sinon.stub(inquirer, 'prompt');
prompt.onFirstCall().resolves({ plan: 'm2' });
prompt.onSecondCall().resolves({ mode: 'DEV' });

await runCommand(['mail:create', '--domain', 'example.com']);

const { choices } = prompt.firstCall.args[0] as any;
expect(choices.map((choice: any) => choice.value)).to.deep.equal(['m2']);
});
});
Loading
Loading