record tests
This commit is contained in:
@@ -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}`));
|
||||
|
||||
+13
-4
@@ -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);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user