Skip to content

Commit

Permalink
test: ✅ add test for graph query helper module
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinxin90 committed Feb 19, 2021
1 parent 2535367 commit 39a7aff
Showing 1 changed file with 83 additions and 7 deletions.
90 changes: 83 additions & 7 deletions __test__/unittest/controllers/QueryGraphHandler/helper.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -317,12 +317,18 @@ describe("Test helper moduler", () => {

describe("Test _getInputCategory function", () => {

test("If edge is reversed, should return the category of the output", () => {
test("If edge is reversed, should return the category of the object", () => {

const edgeObject = {
isReversed() {
return true;
}
},
getObject() {
return nodeObject1
},
getSubject() {
return nodeObject2
},
}
const record = {
$edge_metadata: {
Expand All @@ -339,16 +345,22 @@ describe("Test helper moduler", () => {
}
},
}
const res = helper._getInputID(record);
expect(res).toEqual('output')
const res = helper._getInputCategory(record);
expect(res).toEqual('Node1Type')
})

test("If edge is not reversed, should return the node ID of the subject", () => {

const edgeObject = {
isReversed() {
return false;
}
},
getObject() {
return nodeObject1
},
getSubject() {
return nodeObject2
},
}
const record = {
$edge_metadata: {
Expand All @@ -365,8 +377,8 @@ describe("Test helper moduler", () => {
}
},
}
const res = helper._getInputID(record);
expect(res).toEqual('input')
const res = helper._getInputCategory(record);
expect(res).toEqual('Node2Type')
})
})

Expand Down Expand Up @@ -601,6 +613,38 @@ describe("Test helper moduler", () => {
expect(res).toEqual(['789'])
})

test("If error occurred, return null", () => {

const edgeObject = {
isReversed() {
throw new Error();
}
}
const record = {
$edge_metadata: {
trapi_qEdge_obj: edgeObject
},
$input: {
obj: {
primaryID: "input",
label: 'inputLabel',
curies: ['123', '456']
},
},
$output: {
obj: {
primaryID: "output",
label: 'outputLabel',
curies: [
'789'
]
},
},
}
const res = helper._getInputEquivalentIds(record);
expect(res).toBeNull;
})

test("If edge is not reversed, should return the curies of the subject", () => {

const edgeObject = {
Expand Down Expand Up @@ -675,6 +719,38 @@ describe("Test helper moduler", () => {
})
})

test("If error occurred, return null", () => {

const edgeObject = {
isReversed() {
throw new Error();
}
}
const record = {
$edge_metadata: {
trapi_qEdge_obj: edgeObject
},
$input: {
obj: {
primaryID: "input",
label: 'inputLabel',
curies: ['123', '456']
},
},
$output: {
obj: {
primaryID: "output",
label: 'outputLabel',
curies: [
'789'
]
},
},
}
const res = helper._getOutputEquivalentIds(record);
expect(res).toBeNull;
})

test("If edge is not reversed, should return the curies of the object", () => {

const edgeObject = {
Expand Down

0 comments on commit 39a7aff

Please sign in to comment.