Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
drupal_state
Manage
Activity
Members
Labels
Plan
Wiki
Custom issue tracker
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
project
drupal_state
Merge requests
!40
Add refresh option to getObject
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
Add refresh option to getObject
issue/drupal_state-3240885:3240885-force-fetch-option
into
1.0.x
Overview
1
Commits
5
Pipelines
2
Changes
2
Merged
Jay Huskins
requested to merge
issue/drupal_state-3240885:3240885-force-fetch-option
into
1.0.x
2 years ago
Overview
1
Commits
5
Pipelines
2
Changes
2
Expand
Closes
#3240885
0
0
Merge request reports
Viewing commit
1379df6e
Prev
Next
Show latest version
2 files
+
61
−
0
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
2
Search (e.g. *.vue) (Ctrl+P)
1379df6e
Tests for refresh parameter on getObject and getObjectByPath
· 1379df6e
Jay Huskins
authored
2 years ago
src/__tests__/drupalState.test.ts
+
41
−
0
Options
@@ -130,6 +130,29 @@ describe('drupalState', () => {
expect
(
fetchMock
).
toBeCalledTimes
(
1
);
});
test
(
'
Re-fetch resource if it exists in state but refresh is set to true
'
,
async
()
=>
{
const
store
:
DrupalState
=
new
DrupalState
({
apiBase
:
'
https://dev-ds-demo.pantheonsite.io
'
,
apiPrefix
:
'
jsonapi
'
,
debug
:
true
,
});
store
.
setState
({
dsApiIndex
:
indexResponse
.
links
});
expect
(
await
store
.
getObject
({
objectName
:
'
node--recipe
'
,
id
:
'
33386d32-a87c-44b9-b66b-3dd0bfc38dca
'
,
})
).
toEqual
(
recipesResourceObject1
);
expect
(
await
store
.
getObject
({
objectName
:
'
node--recipe
'
,
id
:
'
33386d32-a87c-44b9-b66b-3dd0bfc38dca
'
,
refresh
:
true
,
})
).
toEqual
(
recipesResourceObject1
);
expect
(
fetchMock
).
toBeCalledTimes
(
2
);
});
test
(
'
Add resource object to local resource state if resource state already exists
'
,
async
()
=>
{
const
store
:
DrupalState
=
new
DrupalState
({
apiBase
:
'
https://dev-ds-demo.pantheonsite.io
'
,
@@ -237,6 +260,24 @@ describe('drupalState', () => {
expect
(
fetchMock
).
toBeCalledTimes
(
2
);
});
test
(
'
Re-fetch object if it exists in local storage but refresh is set to true
'
,
async
()
=>
{
const
store
:
DrupalState
=
new
DrupalState
({
apiBase
:
'
https://dev-ds-demo.pantheonsite.io
'
,
apiPrefix
:
'
jsonapi
'
,
debug
:
true
,
});
expect
(
await
store
.
getObject
({
objectName
:
'
node--recipe
'
})).
toEqual
(
recipesCollectionObject1
);
expect
(
await
store
.
getObject
({
objectName
:
'
node--recipe
'
,
refresh
:
true
})
).
toEqual
(
recipesCollectionObject1
);
// Refresh parameter does not ignore API index local storage.
// We expect one call to API Index and two calls to the object.
expect
(
fetchMock
).
toBeCalledTimes
(
3
);
});
test
(
'
Get API Index from local state if it exists
'
,
async
()
=>
{
const
store
:
DrupalState
=
new
DrupalState
({
apiBase
:
'
https://dev-ds-demo.pantheonsite.io
'
,
Loading