-
Notifications
You must be signed in to change notification settings - Fork 89
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Partik SIngh <[email protected]>
- Loading branch information
Showing
7 changed files
with
87 additions
and
81 deletions.
There are no files selected for viewing
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
} | ||
}); | ||
}); | ||
}); |