Tests for registry-cli #32

Closed
0xmuralik wants to merge 23 commits from murali/tests into main
4 changed files with 54 additions and 17 deletions
Showing only changes of commit 59c709debd - Show all commits

View File

@ -11,6 +11,7 @@
"@types/js-yaml": "^4.0.5",
"@types/lodash": "^4.14.182",
"@types/node": "^17.0.25",
"@types/semver": "^7.3.13",
"@types/yargs": "^17.0.10",
"jest": "^29.5.0",
"ts-jest": "^29.0.5",

View File

@ -1,5 +1,21 @@
import yaml from 'js-yaml'
import fs from 'fs'
import path from 'path'
import semver from 'semver';
const { execSync } = require("child_process");
export const updateRecord = (filePath: string) => {
const resolvedFilePath = path.resolve(process.cwd(), filePath);
const file = fs.readFileSync(resolvedFilePath, 'utf-8')
const data = yaml.load(file) as any;
console.log("Data====",data)
data.record.version=semver.inc(data.record.version, 'patch');
fs.writeFileSync(resolvedFilePath, yaml.dump(data));
};
export const cliTest = (args: any) => {
try{
return JSON.parse(execSync(`./bin/laconic cns ${args}`));

View File

@ -1,4 +1,4 @@
import {cliTest,createBond} from './helper';
import {cliTest,createBond, updateRecord} from './helper';
const args= "record "
const filename = "./test/examples/watcher.yml"
@ -11,20 +11,29 @@ describe("test record",() => {
beforeAll(async () => {
// get bondId
bondId=createBond("aphoton","1000000000")
updateRecord(filename)
});
it("publish record",async ()=>{
const resp=cliTest(args+"publish --filename "+filename+" --bond-id "+bondId);
expect(resp).toBeDefined;
expect(resp).toBeDefined();
console.log(resp.toString())
expect(resp.id).toBeDefined();
recordId=resp.id
});
it("get record",async ()=>{
const resp=cliTest(args+"get --id "+recordId);
expect(resp).toBeDefined;
expect(resp).toBeDefined();
expect(resp.length).toEqual(1);
expect(resp[0].id).toEqual(recordId)
expect(resp[0].bondId).toEqual(bondId)
});
it("list records",async ()=>{
const resp=cliTest(args+"list");
expect(resp).toBeDefined;
expect(resp).toBeDefined();
expect(resp.length).toBeGreaterThan(0);
});
});

View File

@ -1200,6 +1200,11 @@
dependencies:
"@types/node" "*"
"@types/semver@^7.3.13":
version "7.3.13"
resolved "https://registry.npmjs.org/@types/semver/-/semver-7.3.13.tgz"
integrity sha512-21cFJr9z3g5dW8B0CVI9g2O9beqaThGQ6ZFBqHfwhzLDKUxaqTIy3vnfah/UPkfOiF2pLq+tGz+W8RyCskuslw==
"@types/stack-utils@^2.0.0":
version "2.0.1"
resolved "https://registry.npmjs.org/@types/stack-utils/-/stack-utils-2.0.1.tgz"
@ -1531,7 +1536,16 @@ cborg@^1.5.4, cborg@^1.6.0:
resolved "https://registry.npmjs.org/cborg/-/cborg-1.9.1.tgz"
integrity sha512-6xKRdJ89ncwEXJGx9rFMRBNp72UqgYSGt2a88rqsvCLda4OuhRlh3xD2nu+ufrw6h9l94K0cnvyD4WEGpKtRtw==
chalk@^2.0.0, chalk@^2.4.1:
chalk@^2.0.0:
version "2.4.2"
resolved "https://registry.npmjs.org/chalk/-/chalk-2.4.2.tgz"
integrity sha512-Mti+f9lpJNcwF4tWV8/OrTTtF1gZi+f8FqlyAdouralcFWFQWF2+NgCHShjkCb+IFBLq9buZwE1xckQU4peSuQ==
dependencies:
ansi-styles "^3.2.1"
escape-string-regexp "^1.0.5"
supports-color "^5.3.0"
chalk@^2.4.1:
version "2.4.2"
resolved "https://registry.npmjs.org/chalk/-/chalk-2.4.2.tgz"
integrity sha512-Mti+f9lpJNcwF4tWV8/OrTTtF1gZi+f8FqlyAdouralcFWFQWF2+NgCHShjkCb+IFBLq9buZwE1xckQU4peSuQ==
@ -1619,12 +1633,7 @@ concat-map@0.0.1:
resolved "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz"
integrity sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=
convert-source-map@^1.6.0:
version "1.9.0"
resolved "https://registry.npmjs.org/convert-source-map/-/convert-source-map-1.9.0.tgz"
integrity sha512-ASFBup0Mz1uyiIjANan1jzLQami9z1PoYSZCiiYW2FczPbenXc45FZdBZLzOT+r6+iciuEModtmCti+hjaAk0A==
convert-source-map@^1.7.0:
convert-source-map@^1.6.0, convert-source-map@^1.7.0:
version "1.9.0"
resolved "https://registry.npmjs.org/convert-source-map/-/convert-source-map-1.9.0.tgz"
integrity sha512-ASFBup0Mz1uyiIjANan1jzLQami9z1PoYSZCiiYW2FczPbenXc45FZdBZLzOT+r6+iciuEModtmCti+hjaAk0A==
@ -3044,17 +3053,19 @@ secp256k1@^4.0.1:
node-addon-api "^2.0.0"
node-gyp-build "^4.2.0"
semver@^6.0.0:
semver@^6.0.0, semver@^6.3.0:
version "6.3.0"
resolved "https://registry.npmjs.org/semver/-/semver-6.3.0.tgz"
integrity sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==
semver@^6.3.0:
version "6.3.0"
resolved "https://registry.npmjs.org/semver/-/semver-6.3.0.tgz"
integrity sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==
semver@^7.3.5:
version "7.3.7"
resolved "https://registry.npmjs.org/semver/-/semver-7.3.7.tgz"
integrity sha512-QlYTucUYOews+WeEujDoEGziz4K6c47V/Bd+LjSSYcA94p+DmINdf7ncaUinThfvZyu13lN9OY1XDxt8C0Tw0g==
dependencies:
lru-cache "^6.0.0"
semver@^7.3.5, semver@7.x:
semver@7.x:
version "7.3.7"
resolved "https://registry.npmjs.org/semver/-/semver-7.3.7.tgz"
integrity sha512-QlYTucUYOews+WeEujDoEGziz4K6c47V/Bd+LjSSYcA94p+DmINdf7ncaUinThfvZyu13lN9OY1XDxt8C0Tw0g==