Skip to content

Commit

Permalink
Completed Tests
Browse files Browse the repository at this point in the history
Signed-off-by: Partik SIngh <[email protected]>
  • Loading branch information
partik03 committed Aug 25, 2023
1 parent adefa56 commit 525dbff
Show file tree
Hide file tree
Showing 7 changed files with 87 additions and 81 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
"get": "loadbalancer getLoadBalancer",
"update": "loadbalancer updateLoadBalancer",
"list": "loadbalancer listLoadBalancers"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
"get": "loadbalancer getLoadBalancer",
"update": "loadbalancer updateLoadBalancer",
"list": "loadbalancer listLoadBalancers"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
"get": "loadbalancer getLoadBalancer",
"update": "loadbalancer updateLoadBalancer",
"list": "loadbalancer listLoadBalancers"
}
}
162 changes: 84 additions & 78 deletions generator/test/generators/oracle/generator.test.ts
Original file line number Diff line number Diff line change
@@ -1,86 +1,92 @@
import { expect } from "chai";
import { SyntaxKind } from "typescript";
import { expect } from 'chai';
import { SyntaxKind } from 'typescript';

import { extractSDKData } from "../../../generators/oracle/generator";
import { readJsonData,readSourceFile } from "../lib/helper";
import { extractSDKData } from '../../../generators/oracle/generator';
import { readJsonData, readSourceFile } from '../lib/helper';

describe("Oracle generator extractSDKData", () => {
context("with valid methods and valid AST", () => {
it("should return extracted class data", async () => {
const sdkFile: any = await readSourceFile("validDataset", "oracle");
const data: any = await readJsonData(
"validDataset",
"oracle",
"serviceClass"
);
let cloned = null;
sdkFile.forEachChild(child => {
if (SyntaxKind[child.kind] === "ClassDeclaration") {
cloned = Object.assign({}, child);
}
});
describe('Oracle generator extractSDKData', () => {
context('with valid methods and valid AST', () => {
it('should return extracted class data', async () => {
const sdkFile: any = await readSourceFile('validDataset', 'oracle');
const data: any = await readJsonData(
'validDataset',
'oracle',
'serviceClass'
);
let cloned = null;
sdkFile.forEachChild(child => {
if (SyntaxKind[child.kind] === 'ClassDeclaration') {
cloned = Object.assign({}, child);
}
});

if (cloned) {
const result = extractSDKData(cloned, data);
expect(result).to.be.an("object");
expect(result.functions).to.be.an("array");
expect(result.className).to.be.string;
} else {
console.error("Error in cloning class");
}
});
});
if (cloned) {
const result = extractSDKData(cloned, data);
expect(result).to.be.an('object');
expect(result.functions).to.be.an('array');
expect(result.className).to.be.string;
} else {
console.error('Error in cloning class');
}
});
});

context("with invalid method data:missing method name", () => {
it("should drop invalid method", async () => {
const sdkFile: any = await readSourceFile("invalidDataset_1", "oracle");
const data: any = await readJsonData(
"invalidDataset_1",
"oracle",
"serviceClass"
);
let cloned = null;
sdkFile.forEachChild(child => {
if (SyntaxKind[child.kind] === "ClassDeclaration") {
cloned = Object.assign({}, child);
}
});
context('with invalid method data:missing method name', () => {
it('should drop invalid method', async () => {
const sdkFile: any = await readSourceFile(
'invalidDataset_1',
'oracle'
);
const data: any = await readJsonData(
'invalidDataset_1',
'oracle',
'serviceClass'
);
let cloned = null;
sdkFile.forEachChild(child => {
if (SyntaxKind[child.kind] === 'ClassDeclaration') {
cloned = Object.assign({}, child);
}
});

if (cloned) {
expect(
extractSDKData(cloned, data).functions.length <
Object.keys(data).length
).to.be.true;
} else {
console.error("Error in cloning class");
}
});
});
if (cloned) {
expect(
extractSDKData(cloned, data).functions.length <
Object.keys(data).length
).to.be.true;
} else {
console.error('Error in cloning class');
}
});
});

context("Oracle with no functions", () => {
it("should return empty array of methods", async () => {
const sdkFile: any = await readSourceFile("invalidDataset_2", "oracle");
const data: any = await readJsonData(
"invalidDataset_2",
"oracle",
"serviceClass"
);
let cloned = null;
sdkFile.forEachChild(child => {
if (SyntaxKind[child.kind] === "ClassDeclaration") {
cloned = Object.assign({}, child);
}
});
context('Oracle with no functions', () => {
it('should return empty array of methods', async () => {
const sdkFile: any = await readSourceFile(
'invalidDataset_2',
'oracle'
);
const data: any = await readJsonData(
'invalidDataset_2',
'oracle',
'serviceClass'
);
let cloned = null;
sdkFile.forEachChild(child => {
if (SyntaxKind[child.kind] === 'ClassDeclaration') {
cloned = Object.assign({}, child);
}
});

if (cloned) {
const result = extractSDKData(cloned, data);
expect(result).to.be.an("object");
expect(result.functions).to.be.an("array");
expect(result.className).to.be.string;
expect(result.functions.length).to.eql(0);
} else {
console.error("Error in cloning class");
}
});
});
if (cloned) {
const result = extractSDKData(cloned, data);
expect(result).to.be.an('object');
expect(result.functions).to.be.an('array');
expect(result.className).to.be.string;
expect(result.functions.length).to.eql(0);
} else {
console.error('Error in cloning class');
}
});
});
});

0 comments on commit 525dbff

Please sign in to comment.