Skip to content

Commit 82cb6a3

Browse files
Fix cases where indexed ID is modified or deleted
1 parent 32046dd commit 82cb6a3

File tree

1 file changed

+80
-0
lines changed
  • packages/apollo-cli/src/test

1 file changed

+80
-0
lines changed

packages/apollo-cli/src/test/test.ts

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -814,6 +814,86 @@ void describe('Test CLI', () => {
814814
out = JSON.parse(p.stdout)
815815
assert.strictEqual(out.length, 1)
816816
assert.ok(out.at(0)?.type === 'gene')
817+
818+
// Gets feature and child feature that were added manually (not imported)
819+
p = new Shell(
820+
`${apollo} feature add <<EOF
821+
{
822+
"assembly": "vv1",
823+
"refSeq": "ctgA",
824+
"min": 301,
825+
"max": 310,
826+
"type": "match",
827+
"attributes": {"gff_id": ["match1"]},
828+
"children": [
829+
{
830+
"min": 301,
831+
"max": 305,
832+
"type": "match_part",
833+
"attributes": {"gff_id": ["matchPart1"]}
834+
}
835+
]
836+
}
837+
EOF`,
838+
)
839+
p = new Shell(`${apollo} feature get-indexed-id match1 -a vv1`)
840+
out = JSON.parse(p.stdout)
841+
assert.strictEqual(out.length, 1)
842+
assert.ok(p.stdout.includes('match1'))
843+
p = new Shell(`${apollo} feature get-indexed-id matchPart1 -a vv1`)
844+
out = JSON.parse(p.stdout)
845+
assert.strictEqual(out.length, 1)
846+
assert.ok(p.stdout.includes('matchPart1'))
847+
848+
// Doesn't get child feature after it was deleted
849+
const idToDelete = out[0]._id
850+
new Shell(`${apollo} feature delete -i ${idToDelete}`)
851+
p = new Shell(`${apollo} feature get-indexed-id matchPart1 -a vv1`)
852+
assert.deepStrictEqual(p.stdout.trim(), '[]')
853+
854+
// Gets feature after ID was manually added
855+
p = new Shell(
856+
`${apollo} feature add <<EOF
857+
{
858+
"assembly": "vv1",
859+
"refSeq": "ctgA",
860+
"min": 311,
861+
"max": 320,
862+
"type": "match"
863+
}
864+
EOF`,
865+
)
866+
out = JSON.parse(p.stdout)
867+
const { assembly, changes } = out
868+
const { _id, refSeq } = changes[0].addedFeature
869+
new Shell(`${apollo} feature edit-attribute -i ${_id} -a gff_id -v match2`)
870+
p = new Shell(`${apollo} feature get-indexed-id match2 -a vv1`)
871+
out = JSON.parse(p.stdout)
872+
assert.strictEqual(out.length, 1)
873+
assert.ok(p.stdout.includes('match2'))
874+
875+
// Gets child featuer after it was added with an ID
876+
// add-child CLI command doesn't support adding attributes yet, so we'll
877+
// manually do it with curl for testing for neow
878+
p = new Shell(`${apollo} config accessToken`)
879+
const token = p.stdout.trim()
880+
const newChildFeatureID = '69408088d502fc21aea1bb0a'
881+
new Shell(
882+
`curl -X POST http://127.0.0.1:3999/changes -d '{"typeName":"AddFeatureChange","changedIds":["${newChildFeatureID}"],"assembly":"${assembly}","addedFeature":{"_id":"${newChildFeatureID}","refSeq":"${refSeq}","min":311,"max":315,"type":"match_part","attributes":{"gff_id":["matchPart2"]}},"parentFeatureId":"${_id}"}' -H "Content-Type: application/json" -H "Authorization: Bearer ${token}"`,
883+
)
884+
p = new Shell(`${apollo} feature get-indexed-id matchPart2 -a vv1`)
885+
out = JSON.parse(p.stdout)
886+
assert.strictEqual(out.length, 1)
887+
assert.ok(p.stdout.includes('matchPart2'))
888+
889+
// Doesn't get feature or child after IDs were manually removed
890+
new Shell(`${apollo} feature edit-attribute -i ${_id} -a gff_id -d`)
891+
const childId = out[0]._id
892+
new Shell(`${apollo} feature edit-attribute -i ${childId} -a gff_id -d`)
893+
p = new Shell(`${apollo} feature get-indexed-id match2 -a vv1`)
894+
assert.deepStrictEqual(p.stdout.trim(), '[]')
895+
p = new Shell(`${apollo} feature get-indexed-id matchPart2 -a vv1`)
896+
assert.deepStrictEqual(p.stdout.trim(), '[]')
817897
})
818898

819899
void globalThis.itName('Delete features', () => {

0 commit comments

Comments
 (0)