Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
G1lib.js
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
libs
G1lib.js
Commits
6145c4cf
Commit
6145c4cf
authored
4 years ago
by
Millicent Billette
Browse files
Options
Downloads
Patches
Plain Diff
ADD: mockableDeps to data-pod-client
parent
24de8697
No related branches found
No related tags found
No related merge requests found
Pipeline
#12961
passed with warnings
4 years ago
Stage: build
Stage: test
Stage: deploy
Changes
3
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/data-pod-client.mjs
+4
-2
4 additions, 2 deletions
src/data-pod-client.mjs
src/data-pod-client.test.mjs
+13
-3
13 additions, 3 deletions
src/data-pod-client.test.mjs
src/dictionary-tree.test.mjs
+2
-2
2 additions, 2 deletions
src/dictionary-tree.test.mjs
with
19 additions
and
7 deletions
src/data-pod-client.mjs
+
4
−
2
View file @
6145c4cf
import
{
fetch
}
from
'
./context-dependant/generics.mjs
'
;
export
const
mockableDeps
=
{
fetch
};
export
function
DataPodClient
(
hosts
)
{
const
self
=
this
;
self
.
hosts
=
hosts
;
...
...
@@ -8,5 +10,5 @@ export function DataPodClient(hosts) {
}
async
function
query
(
self
,
queryStr
)
{
return
await
(
await
fetch
(
self
.
hosts
[
0
]
+
queryStr
)).
json
();
return
await
(
await
mockableDeps
.
fetch
(
self
.
hosts
[
0
]
+
queryStr
)).
json
();
}
This diff is collapsed.
Click to expand it.
src/data-pod-client.test.mjs
+
13
−
3
View file @
6145c4cf
import
test
from
'
ava
'
;
import
*
as
app
from
'
./data-pod-client.mjs
'
;
test
(
'
dummy
'
,
async
t
=>
{
t
.
true
(
true
);
});
test
(
'
data-pod-client dummy request
'
,
async
t
=>
{
const
hosts
=
[
'
https://dummy/
'
];
const
query
=
'
user/profile/2sZF6j2PkxBDNAqUde7Dgo5x3crkerZpQ4rBqqJGn8QT?&_source=title
'
;
const
expectedResult
=
JSON
.
parse
(
`{
"_index":"user","_type":"profile","_id":"2sZF6j2PkxBDNAqUde7Dgo5x3crkerZpQ4rBqqJGn8QT","_version":11,
"found":true,
"_source":{"title":"[1000i100] Millicent BILLETTE"}
}`
);
app
.
mockableDeps
.
fetch
=
(
str
)
=>
{
return
{
json
:()
=>
expectedResult
};};
const
client
=
new
app
.
DataPodClient
(
hosts
);
const
result
=
await
client
.
query
(
query
);
t
.
is
(
result
.
_source
.
title
,
expectedResult
.
_source
.
title
);
});
This diff is collapsed.
Click to expand it.
src/dictionary-tree.test.mjs
+
2
−
2
View file @
6145c4cf
...
...
@@ -23,8 +23,8 @@ test('multi altCount', t => t.is(app.altCount(app.buildTreeStruct('(a|b|c)(d|e|f
test
(
'
multi level tree altCount
'
,
t
=>
t
.
is
(
app
.
altCount
(
app
.
buildTreeStruct
(
'
a(b(c|d)|e(f|g|h)ij(k|l)|@@@@m)
'
)),
9
));
const
exampleTree
=
()
=>
app
.
buildTreeStruct
(
'
a(b(c|d)|e(f|g(h|i)|j)kl(m|n(o|p)|q(r|s)|t)|(u|v)w)
'
);
console
.
log
(
JSON
.
stringify
(
exampleTree
()));
console
.
log
(
app
.
serialize
(
exampleTree
()));
//
console.log(JSON.stringify(exampleTree()));
//
console.log(app.serialize(exampleTree()));
test
(
'
getAlternative 0
'
,
t
=>
t
.
is
(
app
.
getAlternative
(
0
,
exampleTree
()),
'
abc
'
));
test
(
'
getAlternative 1
'
,
t
=>
t
.
is
(
app
.
getAlternative
(
1
,
exampleTree
()),
'
abd
'
));
test
(
'
getAlternative 2
'
,
t
=>
t
.
is
(
app
.
getAlternative
(
2
,
exampleTree
()),
'
aefklm
'
));
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment