Skip to content
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
617535b
WIP: app create tests
Mortza81 Feb 23, 2025
6b3333a
chore: add tests for app create command
Mortza81 Feb 25, 2025
d4276bf
add: login command tests
Mortza81 Mar 9, 2025
f5b220a
fix typo
Mortza81 Mar 9, 2025
b9449de
chore: account use command tests
Mar 10, 2025
3057076
fix typo
Mar 10, 2025
75fa40a
chore: complete account use command tests
Mortza81 Mar 11, 2025
376d743
start deploy command tests
Mortza81 Mar 13, 2025
c193432
chore: add test for deploy command
Mar 15, 2025
a63bddf
chore: image deployment test
Mortza81 Mar 17, 2025
3b3f17c
WIP: create-archive tests
Mortza81 Mar 18, 2025
15257c7
chore: add some tests for create archive function
Mar 24, 2025
9bdf6fe
chore: complete createArchive tests
Mortza81 Mar 25, 2025
5008e88
chore: complete createArchive tests
Mortza81 Mar 25, 2025
46600d0
chore: change fixtures
Mortza81 Mar 25, 2025
a0cada7
chore: add gitignore in fixtures
Mortza81 Mar 25, 2025
7a70426
delete unnecessary files in fixtures
Mortza81 Mar 29, 2025
195f9c9
Merge branch 'master' into chore/add-tests
Mortza81 Jul 31, 2025
855eaf8
update: tests
Mortza81 Jul 31, 2025
df4807c
chore: refactor getAllFiles()
Mortza81 Aug 8, 2025
30e5f24
fix: return node param
Mortza81 Aug 8, 2025
b75a678
chore: remove unnecessary param in network type
Mortza81 Aug 8, 2025
d401d5b
chore: add ci.yaml
Mortza81 Aug 8, 2025
73c8d3a
Merge branch 'master' into chore/add-tests
Mortza81 Aug 8, 2025
a959c64
chore: remove region from tests
Mortza81 Aug 8, 2025
26cbb92
fix: workflow
Mortza81 Aug 8, 2025
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
777 changes: 756 additions & 21 deletions package-lock.json

Large diffs are not rendered by default.

9 changes: 8 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,27 +35,34 @@
"progress": "2.0.3",
"semver": "7.6.3",
"shamsi-date-converter": "1.0.5",
"sinon": "^19.0.2",
"tar": "7.4.3",
"ua-parser-js": "1.0.38",
"update-notifier": "7.1.0",
"ws": "8.18.0"
},
"devDependencies": {
"@oclif/test": "^4.1.11",
"@types/async-retry": "^1.4.9",
"@types/bytes": "^3.1.5",
"@types/chai": "^5.0.1",
"@types/fs-extra": "^11.0.4",
"@types/inquirer": "^9.0.7",
"@types/jest": "^29.5.14",
"@types/node": "18.15.11",
"@types/progress": "^2.0.7",
"@types/semver": "^7.5.8",
"@types/sinon": "^17.0.4",
"@types/ua-parser-js": "^0.7.39",
"@types/update-notifier": "^6.0.8",
"@types/ws": "^8.5.13",
"chai": "^5.2.0",
"eslint": "^8.53.0",
"eslint-config-oclif": "^5.2.2",
"eslint-config-oclif-typescript": "^3.1.13",
"husky": "^9.1.7",
"mocha": "^11.1.0",
"nock": "^14.0.1",
"oclif": "^4.14.12",
"prettier": "^3.3.3",
"pretty-quick": "^4.0.0",
Expand Down Expand Up @@ -169,7 +176,7 @@
"format": "prettier \"**/*.ts\" \"**/*.js\" \"**/*.json\" --ignore-path ./.prettierignore --write",
"postpack": "rm -f oclif.manifest.json tsconfig.tsbuildinfo",
"prepack": "set -ex; rm -rf lib && tsc -b && oclif manifest && oclif readme",
"test": "NODE_OPTIONS=--experimental-vm-modules jest",
"test": "node --loader ts-node/esm ./node_modules/.bin/mocha --forbid-only --timeout 5000 \"test/**/*.test.ts\"",
"version": "oclif readme && git add README.md",
"readme": "oclif readme",
"prepare": "husky install",
Expand Down
15 changes: 9 additions & 6 deletions src/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,10 @@ export interface IProject {
project_id: string;
created_at: string;
isDeployed: boolean;
network?: string;
network?: {
_id: string;
name: string;
};
}

export interface IGetProjectsResponse {
Expand Down Expand Up @@ -124,14 +127,14 @@ export interface IProjectDetails {
bundlePlanID: string;
fixedIPStatus: string;
created_at: string;
node: {
_id: string;
IP: string;
};
Comment thread
Mortza81 marked this conversation as resolved.
hourlyPrice: number;
isDeployed: boolean;
reservedDiskSpace: number;
network: string;
readOnlyRootFilesystem: boolean;
network: {
_id: string;
name: string;
};
}

export interface IProjectDetailsResponse {
Expand Down
7 changes: 4 additions & 3 deletions src/commands/account/use.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,22 @@ export default class AccountUse extends Command {
async run() {
const { flags } = await this.parse(AccountUse);
const liara_json = await this.readGlobalConfig();

if (
!liara_json ||
!liara_json.accounts ||
Object.keys(liara_json.accounts).length === 0
) {
this.error(
"Please add your accounts via 'liara account:add' command, first."
"Please add your accounts via 'liara account:add' command, first.",
);
}

const name = flags.account || (await this.promptName(liara_json.accounts));
const selectedAccount = liara_json.accounts[name];
!selectedAccount &&
this.error(
`Could not find any account associated with this name ${name}.`
`Could not find any account associated with this name ${name}.`,
);

for (const account of Object.keys(liara_json.accounts)) {
Expand All @@ -45,7 +46,7 @@ export default class AccountUse extends Command {
JSON.stringify({
version: GLOBAL_CONF_VERSION,
accounts: liara_json.accounts,
})
}),
);
this.log(chalk.green('> Auth credentials changed.'));
}
Expand Down
6 changes: 4 additions & 2 deletions src/commands/login.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import AccountAdd from './account/add.js';
import AccountUse from './account/use.js';
import { createDebugLogger } from '../utils/output.js';
import { GLOBAL_CONF_PATH, GLOBAL_CONF_VERSION } from '../constants.js';
import ora from 'ora';

export default class Login extends Command {
static description = 'login to your account';
Expand All @@ -26,6 +27,7 @@ export default class Login extends Command {
};

async run() {
this.spinner = ora();
const { flags } = await this.parse(Login);
const debug = createDebugLogger(flags.debug);

Expand Down Expand Up @@ -75,7 +77,7 @@ export default class Login extends Command {
JSON.stringify({
accounts: currentAccounts,
version: GLOBAL_CONF_VERSION,
})
}),
);

this.spinner.succeed('You have logged in successfully.');
Expand All @@ -93,7 +95,7 @@ export default class Login extends Command {
debug(`${error.message}\n`);

this.spinner.fail(
'Cannot open browser. Browser unavailable or lacks permissions.'
'Cannot open browser. Browser unavailable or lacks permissions.',
);
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/types/network.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@ export default interface INetwork {
_id: string;
name: string;
createdAt: string;
projectCount: number,
databaseCount: number
Comment thread
Mortza81 marked this conversation as resolved.
Outdated
}
201 changes: 201 additions & 0 deletions test/app/create.unit.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,201 @@
import { runCommand } from '@oclif/test';
import nock from 'nock';
import { expect } from 'chai';
import { networks } from '../fixtures/networks/fixture.ts';

describe('app:create', function () {
const api = nock('https://api.liara.ir');

beforeEach(() => {
api.get('/v1/networks').query({ teamID: '' }).reply(200, networks);
});

afterEach(() => {
api.done();
nock.cleanAll();
});

it('creates an app with the specified flags', async () => {
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 { stdout } = await runCommand([
'app:create',
'--app',
'test-app',
'--platform',
'laravel',
'--plan',
'small-g2',
'--feature-plan',
'standard',
'--network',
networks.networks[0].name,
'--read-only',
'true',
]);

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

it('throws an error if app name already exists', async () => {
api
.post('/v1/projects/', {
name: 'test-app',
planID: 'small-g2',
platform: 'laravel',
bundlePlanID: 'standard',
network: networks.networks[0]._id,
readOnlyRootFilesystem: true,
})
.query({ teamID: '' })
.reply(409, {
statusCode: 409,
error: 'Conflict',
message: 'Project exists.',
data: null,
});

const { error } = await runCommand([
'app:create',
'--app',
'test-app',
'--platform',
'laravel',
'--plan',
'small-g2',
'--feature-plan',
'standard',
'--network',
networks.networks[0].name,
'--read-only',
'true',
]);

expect(error?.message).to.equal(
'The app already exists. Please use a unique name for your app.',
);
});

it('throws an error if the network is not found', async () => {
const { error } = await runCommand([
'app:create',
'--app',
'test-app',
'--platform',
'laravel',
'--plan',
'small-g2',
'--feature-plan',
'standard',
'--network',
'not-found',
'--read-only',
'true',
]);

expect(error?.message).to.equal('Network not-found not found.');
});

it('thorws an error if user select a feature plan that is not available for free plan', async () => {
const { error } = await runCommand([
'app:create',
'--app',
'test-app',
'--platform',
'laravel',
'--plan',
'free',
'--feature-plan',
'standard',
'--network',
networks.networks[0].name,
'--read-only',
'true',
]);

expect(error?.message).to.equal(
`Only "free" feature bundle plan is available for free plan.`,
);
});

it('throws an error if the user does not have enough balance', async () => {
api
.post('/v1/projects/', {
name: 'test-app',
planID: 'small-g2',
platform: 'laravel',
bundlePlanID: 'standard',
network: networks.networks[0]._id,
readOnlyRootFilesystem: true,
})
.query({ teamID: '' })
.reply(402);

const { error } = await runCommand([
'app:create',
'--app',
'test-app',
'--platform',
'laravel',
'--plan',
'small-g2',
'--feature-plan',
'standard',
'--network',
networks.networks[0].name,
'--read-only',
'true',
]);

expect(error?.message).to.equal(
'Not enough balance. Please charge your account.',
);
});

it('throws proper error if the app creation fails with status code 500', async () => {
api
.post('/v1/projects/', {
name: 'test-app',
planID: 'small-g2',
platform: 'laravel',
bundlePlanID: 'standard',
network: networks.networks[0]._id,
readOnlyRootFilesystem: true,
})
.query({ teamID: '' })
.reply(500);

const { error } = await runCommand([
'app:create',
'--app',
'test-app',
'--platform',
'laravel',
'--plan',
'small-g2',
'--feature-plan',
'standard',
'--network',
networks.networks[0].name,
'--read-only',
'true',
]);

expect(error?.message).to.equal(`Error: Unable to Create App
Please try the following steps:
1. Check your internet connection.
2. Ensure you have enough balance.
3. Try again later.
4. If you still have problems, please contact support by submitting a ticket at https://console.liara.ir/tickets`);
});
});
Loading