Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
AmendsenProject
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Shaik Janipasha
AmendsenProject
Commits
32ab7c8b
Unverified
Commit
32ab7c8b
authored
Jul 11, 2019
by
Tamika Tannis
Committed by
GitHub
Jul 11, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Cleanup api methods and imports (#219)
parent
42a544e1
Changes
36
Show whitespace changes
Inline
Side-by-side
Showing
36 changed files
with
257 additions
and
270 deletions
+257
-270
index.spec.ts
...plication/static/js/ducks/allTags/api/tests/index.spec.ts
+4
-4
v0.ts
amundsen_application/static/js/ducks/allTags/api/v0.ts
+1
-1
sagas.ts
amundsen_application/static/js/ducks/allTags/sagas.ts
+2
-2
index.spec.ts
...n_application/static/js/ducks/allTags/tests/index.spec.ts
+5
-5
index.spec.ts
...ion/static/js/ducks/announcements/api/tests/index.spec.ts
+5
-5
v0.ts
amundsen_application/static/js/ducks/announcements/api/v0.ts
+1
-1
sagas.ts
amundsen_application/static/js/ducks/announcements/sagas.ts
+2
-2
index.spec.ts
...ication/static/js/ducks/announcements/tests/index.spec.ts
+5
-5
index.spec.ts
...lication/static/js/ducks/bookmark/api/tests/index.spec.ts
+12
-12
sagas.ts
amundsen_application/static/js/ducks/bookmark/sagas.ts
+6
-10
index.spec.ts
..._application/static/js/ducks/bookmark/tests/index.spec.ts
+20
-20
index.spec.ts
...lication/static/js/ducks/feedback/api/tests/index.spec.ts
+3
-3
v0.ts
amundsen_application/static/js/ducks/feedback/api/v0.ts
+1
-1
sagas.ts
amundsen_application/static/js/ducks/feedback/sagas.ts
+2
-2
index.spec.ts
..._application/static/js/ducks/feedback/tests/index.spec.ts
+12
-22
index.spec.ts
...n_application/static/js/ducks/log/api/tests/index.spec.ts
+4
-4
index.spec.ts
...ion/static/js/ducks/popularTables/api/tests/index.spec.ts
+4
-4
v0.ts
amundsen_application/static/js/ducks/popularTables/api/v0.ts
+1
-1
sagas.ts
amundsen_application/static/js/ducks/popularTables/sagas.ts
+2
-2
index.spec.ts
...ication/static/js/ducks/popularTables/tests/index.spec.ts
+8
-14
index.spec.ts
...pplication/static/js/ducks/search/api/tests/index.spec.ts
+46
-16
sagas.ts
amundsen_application/static/js/ducks/search/sagas.ts
+6
-8
index.spec.ts
...en_application/static/js/ducks/search/tests/index.spec.ts
+12
-21
helpers.ts
..._application/static/js/ducks/tableMetadata/api/helpers.ts
+4
-4
index.spec.ts
...ion/static/js/ducks/tableMetadata/api/tests/index.spec.ts
+3
-3
v0.ts
amundsen_application/static/js/ducks/tableMetadata/api/v0.ts
+11
-11
sagas.ts
...application/static/js/ducks/tableMetadata/owners/sagas.ts
+3
-3
index.spec.ts
.../static/js/ducks/tableMetadata/owners/tests/index.spec.ts
+4
-4
sagas.ts
amundsen_application/static/js/ducks/tableMetadata/sagas.ts
+8
-16
sagas.ts
...n_application/static/js/ducks/tableMetadata/tags/sagas.ts
+3
-3
index.spec.ts
...on/static/js/ducks/tableMetadata/tags/tests/index.spec.ts
+4
-4
index.spec.ts
...ication/static/js/ducks/tableMetadata/tests/index.spec.ts
+22
-23
index.spec.ts
..._application/static/js/ducks/user/api/tests/index.spec.ts
+17
-20
v0.ts
amundsen_application/static/js/ducks/user/api/v0.ts
+4
-4
sagas.ts
amundsen_application/static/js/ducks/user/sagas.ts
+5
-5
index.spec.ts
...dsen_application/static/js/ducks/user/tests/index.spec.ts
+5
-5
No files found.
amundsen_application/static/js/ducks/allTags/api/tests/index.spec.ts
View file @
32ab7c8b
...
@@ -2,9 +2,9 @@ import axios, { AxiosResponse } from 'axios';
...
@@ -2,9 +2,9 @@ import axios, { AxiosResponse } from 'axios';
import
{
Tag
}
from
'interfaces'
;
import
{
Tag
}
from
'interfaces'
;
import
{
metadataAllTags
,
AllTagsAPI
}
from
'../v0'
;
import
*
as
API
from
'../v0'
;
describe
(
'
metadata
AllTags'
,
()
=>
{
describe
(
'
get
AllTags'
,
()
=>
{
it
(
'resolves with array of sorted result of response.data.tags on success'
,
async
()
=>
{
it
(
'resolves with array of sorted result of response.data.tags on success'
,
async
()
=>
{
const
rawTags
:
Tag
[]
=
[
const
rawTags
:
Tag
[]
=
[
{
tag_count
:
2
,
tag_name
:
'test'
},
{
tag_count
:
2
,
tag_name
:
'test'
},
...
@@ -14,7 +14,7 @@ describe('metadataAllTags', () => {
...
@@ -14,7 +14,7 @@ describe('metadataAllTags', () => {
{
tag_count
:
1
,
tag_name
:
'atest'
},
{
tag_count
:
1
,
tag_name
:
'atest'
},
{
tag_count
:
2
,
tag_name
:
'test'
}
{
tag_count
:
2
,
tag_name
:
'test'
}
];
];
const
mockResponse
:
AxiosResponse
<
AllTagsAPI
>
=
{
const
mockResponse
:
AxiosResponse
<
A
PI
.
A
llTagsAPI
>
=
{
data
:
{
data
:
{
tags
:
rawTags
,
tags
:
rawTags
,
msg
:
'Success'
msg
:
'Success'
...
@@ -27,7 +27,7 @@ describe('metadataAllTags', () => {
...
@@ -27,7 +27,7 @@ describe('metadataAllTags', () => {
const
axiosMock
=
jest
.
spyOn
(
axios
,
'get'
).
mockImplementation
(()
=>
Promise
.
resolve
(
mockResponse
));
const
axiosMock
=
jest
.
spyOn
(
axios
,
'get'
).
mockImplementation
(()
=>
Promise
.
resolve
(
mockResponse
));
expect
.
assertions
(
1
);
expect
.
assertions
(
1
);
await
metadata
AllTags
().
then
(
sortedTags
=>
{
await
API
.
get
AllTags
().
then
(
sortedTags
=>
{
expect
(
sortedTags
).
toEqual
(
expectedTags
);
expect
(
sortedTags
).
toEqual
(
expectedTags
);
});
});
});
});
...
...
amundsen_application/static/js/ducks/allTags/api/v0.ts
View file @
32ab7c8b
...
@@ -8,7 +8,7 @@ export type AllTagsAPI = {
...
@@ -8,7 +8,7 @@ export type AllTagsAPI = {
tags
:
Tag
[];
tags
:
Tag
[];
};
};
export
function
metadata
AllTags
()
{
export
function
get
AllTags
()
{
return
axios
.
get
(
'/api/metadata/v0/tags'
).
then
((
response
:
AxiosResponse
<
AllTagsAPI
>
)
=>
{
return
axios
.
get
(
'/api/metadata/v0/tags'
).
then
((
response
:
AxiosResponse
<
AllTagsAPI
>
)
=>
{
return
response
.
data
.
tags
.
sort
(
sortTagsAlphabetical
);
return
response
.
data
.
tags
.
sort
(
sortTagsAlphabetical
);
})
})
...
...
amundsen_application/static/js/ducks/allTags/sagas.ts
View file @
32ab7c8b
import
{
SagaIterator
}
from
'redux-saga'
;
import
{
SagaIterator
}
from
'redux-saga'
;
import
{
call
,
put
,
takeEvery
}
from
'redux-saga/effects'
;
import
{
call
,
put
,
takeEvery
}
from
'redux-saga/effects'
;
import
{
metadataAllTags
}
from
'./api/v0'
;
import
*
as
API
from
'./api/v0'
;
import
{
getAllTagsFailure
,
getAllTagsSuccess
}
from
'./reducer'
;
import
{
getAllTagsFailure
,
getAllTagsSuccess
}
from
'./reducer'
;
import
{
GetAllTags
}
from
'./types'
;
import
{
GetAllTags
}
from
'./types'
;
export
function
*
getAllTagsWorker
():
SagaIterator
{
export
function
*
getAllTagsWorker
():
SagaIterator
{
try
{
try
{
const
tags
=
yield
call
(
metadata
AllTags
);
const
tags
=
yield
call
(
API
.
get
AllTags
);
yield
put
(
getAllTagsSuccess
(
tags
));
yield
put
(
getAllTagsSuccess
(
tags
));
}
catch
(
e
)
{
}
catch
(
e
)
{
yield
put
(
getAllTagsFailure
());
yield
put
(
getAllTagsFailure
());
...
...
amundsen_application/static/js/ducks/allTags/tests/index.spec.ts
View file @
32ab7c8b
...
@@ -2,7 +2,7 @@ import { expectSaga, testSaga } from 'redux-saga-test-plan';
...
@@ -2,7 +2,7 @@ import { expectSaga, testSaga } from 'redux-saga-test-plan';
import
*
as
matchers
from
'redux-saga-test-plan/matchers'
;
import
*
as
matchers
from
'redux-saga-test-plan/matchers'
;
import
{
throwError
}
from
'redux-saga-test-plan/providers'
;
import
{
throwError
}
from
'redux-saga-test-plan/providers'
;
import
{
metadataAllTags
}
from
'../api/v0'
;
import
*
as
API
from
'../api/v0'
;
import
reducer
,
{
import
reducer
,
{
getAllTags
,
getAllTagsFailure
,
getAllTagsSuccess
,
getAllTags
,
getAllTagsFailure
,
getAllTagsSuccess
,
initialState
,
AllTagsReducerState
initialState
,
AllTagsReducerState
...
@@ -69,8 +69,8 @@ describe('allTags ducks', () => {
...
@@ -69,8 +69,8 @@ describe('allTags ducks', () => {
describe
(
'getAllTagsWatcher'
,
()
=>
{
describe
(
'getAllTagsWatcher'
,
()
=>
{
it
(
'takes GetAllTags.REQUEST with getAllTagsWorker'
,
()
=>
{
it
(
'takes GetAllTags.REQUEST with getAllTagsWorker'
,
()
=>
{
testSaga
(
getAllTagsWatcher
)
testSaga
(
getAllTagsWatcher
)
.
next
()
.
next
()
.
takeEvery
(
GetAllTags
.
REQUEST
,
getAllTagsWorker
)
.
takeEvery
(
GetAllTags
.
REQUEST
,
getAllTagsWorker
);
.
next
().
isDone
(
);
});
});
});
});
...
@@ -79,7 +79,7 @@ describe('allTags ducks', () => {
...
@@ -79,7 +79,7 @@ describe('allTags ducks', () => {
const
mockTags
=
[{
tag_count
:
2
,
tag_name
:
'test'
},
{
tag_count
:
1
,
tag_name
:
'test2'
}];
const
mockTags
=
[{
tag_count
:
2
,
tag_name
:
'test'
},
{
tag_count
:
1
,
tag_name
:
'test2'
}];
return
expectSaga
(
getAllTagsWorker
)
return
expectSaga
(
getAllTagsWorker
)
.
provide
([
.
provide
([
[
matchers
.
call
.
fn
(
metadata
AllTags
),
mockTags
],
[
matchers
.
call
.
fn
(
API
.
get
AllTags
),
mockTags
],
])
])
.
put
(
getAllTagsSuccess
(
mockTags
))
.
put
(
getAllTagsSuccess
(
mockTags
))
.
run
();
.
run
();
...
@@ -88,7 +88,7 @@ describe('allTags ducks', () => {
...
@@ -88,7 +88,7 @@ describe('allTags ducks', () => {
it
(
'handles request error'
,
()
=>
{
it
(
'handles request error'
,
()
=>
{
return
expectSaga
(
getAllTagsWorker
)
return
expectSaga
(
getAllTagsWorker
)
.
provide
([
.
provide
([
[
matchers
.
call
.
fn
(
metadata
AllTags
),
throwError
(
new
Error
())],
[
matchers
.
call
.
fn
(
API
.
get
AllTags
),
throwError
(
new
Error
())],
])
])
.
put
(
getAllTagsFailure
())
.
put
(
getAllTagsFailure
())
.
run
();
.
run
();
...
...
amundsen_application/static/js/ducks/announcements/api/tests/index.spec.ts
View file @
32ab7c8b
...
@@ -2,13 +2,13 @@ import axios, { AxiosResponse } from 'axios';
...
@@ -2,13 +2,13 @@ import axios, { AxiosResponse } from 'axios';
import
{
AnnouncementPost
}
from
'interfaces'
;
import
{
AnnouncementPost
}
from
'interfaces'
;
import
{
announcementsGet
,
AnnouncementsAPI
}
from
'../v0'
;
import
*
as
API
from
'../v0'
;
jest
.
mock
(
'axios'
);
jest
.
mock
(
'axios'
);
describe
(
'
announcementsGet
'
,
()
=>
{
describe
(
'
getAnnouncements
'
,
()
=>
{
let
expectedPosts
:
AnnouncementPost
[];
let
expectedPosts
:
AnnouncementPost
[];
let
mockResponse
:
AxiosResponse
<
AnnouncementsAPI
>
;
let
mockResponse
:
AxiosResponse
<
A
PI
.
A
nnouncementsAPI
>
;
beforeAll
(()
=>
{
beforeAll
(()
=>
{
expectedPosts
=
[{
date
:
'12/31/1999'
,
title
:
'Test'
,
html_content
:
'<div>Test content</div>'
}];
expectedPosts
=
[{
date
:
'12/31/1999'
,
title
:
'Test'
,
html_content
:
'<div>Test content</div>'
}];
mockResponse
=
{
mockResponse
=
{
...
@@ -27,7 +27,7 @@ describe('announcementsGet', () => {
...
@@ -27,7 +27,7 @@ describe('announcementsGet', () => {
it
(
'resolves with array of posts from response.data on success'
,
async
()
=>
{
it
(
'resolves with array of posts from response.data on success'
,
async
()
=>
{
expect
.
assertions
(
1
);
expect
.
assertions
(
1
);
await
announcementsGet
().
then
(
posts
=>
{
await
API
.
getAnnouncements
().
then
(
posts
=>
{
expect
(
posts
).
toEqual
(
expectedPosts
);
expect
(
posts
).
toEqual
(
expectedPosts
);
});
});
});
});
...
...
amundsen_application/static/js/ducks/announcements/api/v0.ts
View file @
32ab7c8b
...
@@ -7,7 +7,7 @@ export type AnnouncementsAPI = {
...
@@ -7,7 +7,7 @@ export type AnnouncementsAPI = {
posts
:
AnnouncementPost
[];
posts
:
AnnouncementPost
[];
};
};
export
function
announcementsGet
()
{
export
function
getAnnouncements
()
{
return
axios
({
return
axios
({
method
:
'get'
,
method
:
'get'
,
url
:
'/api/announcements/v0/'
,
url
:
'/api/announcements/v0/'
,
...
...
amundsen_application/static/js/ducks/announcements/sagas.ts
View file @
32ab7c8b
import
{
SagaIterator
}
from
'redux-saga'
;
import
{
SagaIterator
}
from
'redux-saga'
;
import
{
call
,
put
,
takeEvery
}
from
'redux-saga/effects'
;
import
{
call
,
put
,
takeEvery
}
from
'redux-saga/effects'
;
import
{
announcementsGet
}
from
'./api/v0'
;
import
*
as
API
from
'./api/v0'
;
import
{
getAnnouncementsFailure
,
getAnnouncementsSuccess
}
from
'./reducer'
;
import
{
getAnnouncementsFailure
,
getAnnouncementsSuccess
}
from
'./reducer'
;
import
{
GetAnnouncements
}
from
'./types'
;
import
{
GetAnnouncements
}
from
'./types'
;
export
function
*
getAnnouncementsWorker
():
SagaIterator
{
export
function
*
getAnnouncementsWorker
():
SagaIterator
{
try
{
try
{
const
posts
=
yield
call
(
announcementsGet
);
const
posts
=
yield
call
(
API
.
getAnnouncements
);
yield
put
(
getAnnouncementsSuccess
(
posts
));
yield
put
(
getAnnouncementsSuccess
(
posts
));
}
catch
(
e
)
{
}
catch
(
e
)
{
yield
put
(
getAnnouncementsFailure
());
yield
put
(
getAnnouncementsFailure
());
...
...
amundsen_application/static/js/ducks/announcements/tests/index.spec.ts
View file @
32ab7c8b
...
@@ -2,7 +2,7 @@ import { expectSaga, testSaga } from 'redux-saga-test-plan';
...
@@ -2,7 +2,7 @@ import { expectSaga, testSaga } from 'redux-saga-test-plan';
import
*
as
matchers
from
'redux-saga-test-plan/matchers'
;
import
*
as
matchers
from
'redux-saga-test-plan/matchers'
;
import
{
throwError
}
from
'redux-saga-test-plan/providers'
;
import
{
throwError
}
from
'redux-saga-test-plan/providers'
;
import
{
announcementsGet
}
from
'../api/v0'
;
import
*
as
API
from
'../api/v0'
;
import
reducer
,
{
import
reducer
,
{
getAnnouncements
,
getAnnouncementsFailure
,
getAnnouncementsSuccess
,
getAnnouncements
,
getAnnouncementsFailure
,
getAnnouncementsSuccess
,
initialState
,
AnnouncementsReducerState
initialState
,
AnnouncementsReducerState
...
@@ -60,8 +60,8 @@ describe('announcements ducks', () => {
...
@@ -60,8 +60,8 @@ describe('announcements ducks', () => {
describe
(
'getAnnouncementsWatcher'
,
()
=>
{
describe
(
'getAnnouncementsWatcher'
,
()
=>
{
it
(
'takes GetAnnouncements.REQUEST with getAnnouncementsWorker'
,
()
=>
{
it
(
'takes GetAnnouncements.REQUEST with getAnnouncementsWorker'
,
()
=>
{
testSaga
(
getAnnouncementsWatcher
)
testSaga
(
getAnnouncementsWatcher
)
.
next
()
.
next
()
.
takeEvery
(
GetAnnouncements
.
REQUEST
,
getAnnouncementsWorker
)
.
takeEvery
(
GetAnnouncements
.
REQUEST
,
getAnnouncementsWorker
);
.
next
().
isDone
(
);
});
});
});
});
...
@@ -70,7 +70,7 @@ describe('announcements ducks', () => {
...
@@ -70,7 +70,7 @@ describe('announcements ducks', () => {
const
mockPosts
=
[{
date
:
'12/31/1999'
,
title
:
'Test'
,
html_content
:
'<div>Test content</div>'
}];
const
mockPosts
=
[{
date
:
'12/31/1999'
,
title
:
'Test'
,
html_content
:
'<div>Test content</div>'
}];
return
expectSaga
(
getAnnouncementsWorker
)
return
expectSaga
(
getAnnouncementsWorker
)
.
provide
([
.
provide
([
[
matchers
.
call
.
fn
(
announcementsGet
),
mockPosts
],
[
matchers
.
call
.
fn
(
API
.
getAnnouncements
),
mockPosts
],
])
])
.
put
(
getAnnouncementsSuccess
(
mockPosts
))
.
put
(
getAnnouncementsSuccess
(
mockPosts
))
.
run
();
.
run
();
...
@@ -79,7 +79,7 @@ describe('announcements ducks', () => {
...
@@ -79,7 +79,7 @@ describe('announcements ducks', () => {
it
(
'handles request error'
,
()
=>
{
it
(
'handles request error'
,
()
=>
{
return
expectSaga
(
getAnnouncementsWorker
)
return
expectSaga
(
getAnnouncementsWorker
)
.
provide
([
.
provide
([
[
matchers
.
call
.
fn
(
announcementsGet
),
throwError
(
new
Error
())],
[
matchers
.
call
.
fn
(
API
.
getAnnouncements
),
throwError
(
new
Error
())],
])
])
.
put
(
getAnnouncementsFailure
())
.
put
(
getAnnouncementsFailure
())
.
run
();
.
run
();
...
...
amundsen_application/static/js/ducks/bookmark/api/tests/index.spec.ts
View file @
32ab7c8b
...
@@ -2,7 +2,7 @@ import axios, { AxiosResponse } from 'axios';
...
@@ -2,7 +2,7 @@ import axios, { AxiosResponse } from 'axios';
import
{
Bookmark
}
from
'interfaces'
;
import
{
Bookmark
}
from
'interfaces'
;
import
{
addBookmark
,
getBookmarks
,
removeBookmark
,
API_PATH
}
from
'../v0'
;
import
*
as
API
from
'../v0'
;
jest
.
mock
(
'axios'
);
jest
.
mock
(
'axios'
);
...
@@ -25,14 +25,14 @@ describe('addBookmark', () => {
...
@@ -25,14 +25,14 @@ describe('addBookmark', () => {
it
(
'calls axios with correct parameters'
,
async
()
=>
{
it
(
'calls axios with correct parameters'
,
async
()
=>
{
expect
.
assertions
(
1
);
expect
.
assertions
(
1
);
await
addBookmark
(
'test'
,
'table'
).
then
(
data
=>
{
await
API
.
addBookmark
(
'test'
,
'table'
).
then
(
data
=>
{
expect
(
axiosMock
).
toHaveBeenCalledWith
(
`
${
API_PATH
}
/user/bookmark`
,
{
type
:
'table'
,
key
:
'test'
});
expect
(
axiosMock
).
toHaveBeenCalledWith
(
`
${
API
.
API
_PATH
}
/user/bookmark`
,
{
type
:
'table'
,
key
:
'test'
});
});
});
});
});
it
(
'returns response data'
,
async
()
=>
{
it
(
'returns response data'
,
async
()
=>
{
expect
.
assertions
(
1
);
expect
.
assertions
(
1
);
await
addBookmark
(
'test'
,
'table'
).
then
(
data
=>
{
await
API
.
addBookmark
(
'test'
,
'table'
).
then
(
data
=>
{
expect
(
data
).
toEqual
(
mockPutResponse
.
data
);
expect
(
data
).
toEqual
(
mockPutResponse
.
data
);
});
});
});
});
...
@@ -61,21 +61,21 @@ describe('getBookmarks', () => {
...
@@ -61,21 +61,21 @@ describe('getBookmarks', () => {
it
(
'calls axios with correct parameters if userId provided'
,
async
()
=>
{
it
(
'calls axios with correct parameters if userId provided'
,
async
()
=>
{
expect
.
assertions
(
1
);
expect
.
assertions
(
1
);
await
getBookmarks
(
'testUserId'
).
then
(
data
=>
{
await
API
.
getBookmarks
(
'testUserId'
).
then
(
data
=>
{
expect
(
axiosMock
).
toHaveBeenCalledWith
(
`
${
API_PATH
}
/user/bookmark?user_id=testUserId`
);
expect
(
axiosMock
).
toHaveBeenCalledWith
(
`
${
API
.
API
_PATH
}
/user/bookmark?user_id=testUserId`
);
});
});
});
});
it
(
'calls axios with correct parameters if userId not provided'
,
async
()
=>
{
it
(
'calls axios with correct parameters if userId not provided'
,
async
()
=>
{
expect
.
assertions
(
1
);
expect
.
assertions
(
1
);
await
getBookmarks
().
then
(
data
=>
{
await
API
.
getBookmarks
().
then
(
data
=>
{
expect
(
axiosMock
).
toHaveBeenCalledWith
(
`
${
API_PATH
}
/user/bookmark`
);
expect
(
axiosMock
).
toHaveBeenCalledWith
(
`
${
API
.
API
_PATH
}
/user/bookmark`
);
});
});
});
});
it
(
'returns response data'
,
async
()
=>
{
it
(
'returns response data'
,
async
()
=>
{
expect
.
assertions
(
1
);
expect
.
assertions
(
1
);
await
getBookmarks
(
'testUserId'
).
then
(
data
=>
{
await
API
.
getBookmarks
(
'testUserId'
).
then
(
data
=>
{
expect
(
data
).
toEqual
(
mockGetResponse
.
data
);
expect
(
data
).
toEqual
(
mockGetResponse
.
data
);
});
});
});
});
...
@@ -105,14 +105,14 @@ describe('removeBookmark', () => {
...
@@ -105,14 +105,14 @@ describe('removeBookmark', () => {
it
(
'calls axios with correct parameters'
,
async
()
=>
{
it
(
'calls axios with correct parameters'
,
async
()
=>
{
expect
.
assertions
(
1
);
expect
.
assertions
(
1
);
await
removeBookmark
(
'testKey'
,
'table'
).
then
(
data
=>
{
await
API
.
removeBookmark
(
'testKey'
,
'table'
).
then
(
data
=>
{
expect
(
axiosMock
).
toHaveBeenCalledWith
(
`
${
API_PATH
}
/user/bookmark`
,
{
data
:
{
type
:
'table'
,
key
:
'testKey'
}});
expect
(
axiosMock
).
toHaveBeenCalledWith
(
`
${
API
.
API
_PATH
}
/user/bookmark`
,
{
data
:
{
type
:
'table'
,
key
:
'testKey'
}});
});
});
});
});
it
(
'returns response data'
,
async
()
=>
{
it
(
'returns response data'
,
async
()
=>
{
expect
.
assertions
(
1
);
expect
.
assertions
(
1
);
await
removeBookmark
(
'test'
,
'table'
).
then
(
data
=>
{
await
API
.
removeBookmark
(
'test'
,
'table'
).
then
(
data
=>
{
expect
(
data
).
toEqual
(
mockDeleteResponse
.
data
);
expect
(
data
).
toEqual
(
mockDeleteResponse
.
data
);
});
});
});
});
...
...
amundsen_application/static/js/ducks/bookmark/sagas.ts
View file @
32ab7c8b
import
{
SagaIterator
}
from
'redux-saga'
;
import
{
SagaIterator
}
from
'redux-saga'
;
import
{
call
,
put
,
takeEvery
}
from
'redux-saga/effects'
;
import
{
call
,
put
,
takeEvery
}
from
'redux-saga/effects'
;
import
{
import
*
as
API
from
'./api/v0'
;
addBookmark
,
removeBookmark
,
getBookmarks
,
}
from
'./api/v0'
;
import
{
import
{
addBookmarkFailure
,
addBookmarkFailure
,
...
@@ -34,10 +30,10 @@ export function* addBookmarkWorker(action: AddBookmarkRequest): SagaIterator {
...
@@ -34,10 +30,10 @@ export function* addBookmarkWorker(action: AddBookmarkRequest): SagaIterator {
const
{
resourceKey
,
resourceType
}
=
action
.
payload
;
const
{
resourceKey
,
resourceType
}
=
action
.
payload
;
try
{
try
{
yield
call
(
addBookmark
,
resourceKey
,
resourceType
);
yield
call
(
API
.
addBookmark
,
resourceKey
,
resourceType
);
// TODO - Consider adding the newly bookmarked resource directly to local store. This would save a round trip.
// TODO - Consider adding the newly bookmarked resource directly to local store. This would save a round trip.
response
=
yield
call
(
getBookmarks
);
response
=
yield
call
(
API
.
getBookmarks
);
yield
put
(
addBookmarkSuccess
(
response
.
bookmarks
));
yield
put
(
addBookmarkSuccess
(
response
.
bookmarks
));
}
catch
(
e
)
{
}
catch
(
e
)
{
yield
put
(
addBookmarkFailure
());
yield
put
(
addBookmarkFailure
());
...
@@ -52,7 +48,7 @@ export function* removeBookmarkWorker(action: RemoveBookmarkRequest): SagaIterat
...
@@ -52,7 +48,7 @@ export function* removeBookmarkWorker(action: RemoveBookmarkRequest): SagaIterat
let
response
;
let
response
;
const
{
resourceKey
,
resourceType
}
=
action
.
payload
;
const
{
resourceKey
,
resourceType
}
=
action
.
payload
;
try
{
try
{
response
=
yield
call
(
removeBookmark
,
resourceKey
,
resourceType
);
response
=
yield
call
(
API
.
removeBookmark
,
resourceKey
,
resourceType
);
yield
put
(
removeBookmarkSuccess
(
resourceKey
,
resourceType
));
yield
put
(
removeBookmarkSuccess
(
resourceKey
,
resourceType
));
}
catch
(
e
)
{
}
catch
(
e
)
{
yield
put
(
removeBookmarkFailure
());
yield
put
(
removeBookmarkFailure
());
...
@@ -66,7 +62,7 @@ export function* removeBookmarkWatcher(): SagaIterator {
...
@@ -66,7 +62,7 @@ export function* removeBookmarkWatcher(): SagaIterator {
export
function
*
getBookmarksWorker
(
action
:
GetBookmarksRequest
):
SagaIterator
{
export
function
*
getBookmarksWorker
(
action
:
GetBookmarksRequest
):
SagaIterator
{
let
response
;
let
response
;
try
{
try
{
response
=
yield
call
(
getBookmarks
);
response
=
yield
call
(
API
.
getBookmarks
);
yield
put
(
getBookmarksSuccess
(
response
.
bookmarks
));
yield
put
(
getBookmarksSuccess
(
response
.
bookmarks
));
}
catch
(
e
)
{
}
catch
(
e
)
{
yield
put
(
getBookmarksFailure
());
yield
put
(
getBookmarksFailure
());
...
@@ -81,7 +77,7 @@ export function* getBookmarkForUserWorker(action: GetBookmarksForUserRequest): S
...
@@ -81,7 +77,7 @@ export function* getBookmarkForUserWorker(action: GetBookmarksForUserRequest): S
let
response
;
let
response
;
const
{
userId
}
=
action
.
payload
;
const
{
userId
}
=
action
.
payload
;
try
{
try
{
response
=
yield
call
(
getBookmarks
,
userId
);
response
=
yield
call
(
API
.
getBookmarks
,
userId
);
yield
put
(
getBookmarksForUserSuccess
(
response
.
bookmarks
));
yield
put
(
getBookmarksForUserSuccess
(
response
.
bookmarks
));
}
catch
(
e
)
{
}
catch
(
e
)
{
yield
put
(
getBookmarksForUserFailure
());
yield
put
(
getBookmarksForUserFailure
());
...
...
amundsen_application/static/js/ducks/bookmark/tests/index.spec.ts
View file @
32ab7c8b
...
@@ -4,7 +4,7 @@ import { throwError } from 'redux-saga-test-plan/providers';
...
@@ -4,7 +4,7 @@ import { throwError } from 'redux-saga-test-plan/providers';
import
{
Bookmark
,
ResourceType
}
from
'interfaces'
;
import
{
Bookmark
,
ResourceType
}
from
'interfaces'
;
import
{
addBookmark
as
addBkmrk
,
getBookmarks
as
getBkmrks
,
removeBookmark
as
removeBkmrk
}
from
'../api/v0'
;
import
*
as
API
from
'../api/v0'
;
import
reducer
,
{
import
reducer
,
{
addBookmark
,
addBookmarkFailure
,
addBookmarkSuccess
,
addBookmark
,
addBookmarkFailure
,
addBookmarkSuccess
,
getBookmarks
,
getBookmarksFailure
,
getBookmarksSuccess
,
getBookmarks
,
getBookmarksFailure
,
getBookmarksSuccess
,
...
@@ -222,8 +222,8 @@ describe('bookmark ducks', () => {
...
@@ -222,8 +222,8 @@ describe('bookmark ducks', () => {
describe
(
'addBookmarkWatcher'
,
()
=>
{
describe
(
'addBookmarkWatcher'
,
()
=>
{
it
(
'takes AddBookmark.REQUEST with addBookmarkWorker'
,
()
=>
{
it
(
'takes AddBookmark.REQUEST with addBookmarkWorker'
,
()
=>
{
testSaga
(
addBookmarkWatcher
)
testSaga
(
addBookmarkWatcher
)
.
next
()
.
next
()
.
takeEvery
(
AddBookmark
.
REQUEST
,
addBookmarkWorker
)
.
takeEvery
(
AddBookmark
.
REQUEST
,
addBookmarkWorker
);
.
next
().
isDone
(
);
});
});
});
});
...
@@ -236,8 +236,8 @@ describe('bookmark ducks', () => {
...
@@ -236,8 +236,8 @@ describe('bookmark ducks', () => {
it
(
'adds a bookmark'
,
()
=>
{
it
(
'adds a bookmark'
,
()
=>
{
return
expectSaga
(
addBookmarkWorker
,
action
)
return
expectSaga
(
addBookmarkWorker
,
action
)
.
provide
([
.
provide
([
[
matchers
.
call
.
fn
(
addBkm
rk
),
{}],
[
matchers
.
call
.
fn
(
API
.
addBookma
rk
),
{}],
[
matchers
.
call
.
fn
(
getBkm
rks
),
{
bookmarks
}],
[
matchers
.
call
.
fn
(
API
.
getBookma
rks
),
{
bookmarks
}],
])
])
.
put
(
addBookmarkSuccess
(
bookmarks
))
.
put
(
addBookmarkSuccess
(
bookmarks
))
.
run
();
.
run
();
...
@@ -246,8 +246,8 @@ describe('bookmark ducks', () => {
...
@@ -246,8 +246,8 @@ describe('bookmark ducks', () => {
it
(
'handles request error'
,
()
=>
{
it
(
'handles request error'
,
()
=>
{
return
expectSaga
(
addBookmarkWorker
,
action
)
return
expectSaga
(
addBookmarkWorker
,
action
)
.
provide
([
.
provide
([
[
matchers
.
call
.
fn
(
addBkm
rk
),
throwError
(
new
Error
())],
[
matchers
.
call
.
fn
(
API
.
addBookma
rk
),
throwError
(
new
Error
())],
[
matchers
.
call
.
fn
(
getBkm
rks
),
throwError
(
new
Error
())],
[
matchers
.
call
.
fn
(
API
.
getBookma
rks
),
throwError
(
new
Error
())],
])
])
.
put
(
addBookmarkFailure
())
.
put
(
addBookmarkFailure
())
.
run
();
.
run
();
...
@@ -257,8 +257,8 @@ describe('bookmark ducks', () => {
...
@@ -257,8 +257,8 @@ describe('bookmark ducks', () => {
describe
(
'getBookmarksWatcher'
,
()
=>
{
describe
(
'getBookmarksWatcher'
,
()
=>
{
it
(
'takes GetBookmark.REQUEST with getBookmarksWorker'
,
()
=>
{
it
(
'takes GetBookmark.REQUEST with getBookmarksWorker'
,
()
=>
{
testSaga
(
getBookmarksWatcher
)
testSaga
(
getBookmarksWatcher
)
.
next
()
.
next
()
.
takeEvery
(
GetBookmarks
.
REQUEST
,
getBookmarksWorker
)
.
takeEvery
(
GetBookmarks
.
REQUEST
,
getBookmarksWorker
);
.
next
().
isDone
(
);
});
});
});
});
...
@@ -266,7 +266,7 @@ describe('bookmark ducks', () => {
...
@@ -266,7 +266,7 @@ describe('bookmark ducks', () => {
it
(
'gets bookmarks'
,
()
=>
{
it
(
'gets bookmarks'
,
()
=>
{
return
expectSaga
(
getBookmarksWorker
)
return
expectSaga
(
getBookmarksWorker
)
.
provide
([
.
provide
([
[
matchers
.
call
.
fn
(
getBkm
rks
),
{
bookmarks
}],
[
matchers
.
call
.
fn
(
API
.
getBookma
rks
),
{
bookmarks
}],
])
])
.
put
(
getBookmarksSuccess
(
bookmarks
))
.
put
(
getBookmarksSuccess
(
bookmarks
))
.
run
();
.
run
();
...
@@ -275,7 +275,7 @@ describe('bookmark ducks', () => {
...
@@ -275,7 +275,7 @@ describe('bookmark ducks', () => {
it
(
'handles request error'
,
()
=>
{
it
(
'handles request error'
,
()
=>
{
return
expectSaga
(
getBookmarksWorker
)
return
expectSaga
(
getBookmarksWorker
)
.
provide
([
.
provide
([
[
matchers
.
call
.
fn
(
getBkm
rks
),
throwError
(
new
Error
())],
[
matchers
.
call
.
fn
(
API
.
getBookma
rks
),
throwError
(
new
Error
())],
])
])
.
put
(
getBookmarksFailure
())
.
put
(
getBookmarksFailure
())
.
run
();
.
run
();
...
@@ -285,8 +285,8 @@ describe('bookmark ducks', () => {
...
@@ -285,8 +285,8 @@ describe('bookmark ducks', () => {
describe
(
'getBookmarksForUserWatcher'
,
()
=>
{
describe
(
'getBookmarksForUserWatcher'
,
()
=>
{
it
(
'takes GetBookmarksForUser.REQUEST with getBookmarkForUserWorker'
,
()
=>
{
it
(
'takes GetBookmarksForUser.REQUEST with getBookmarkForUserWorker'
,
()
=>
{
testSaga
(
getBookmarksForUserWatcher
)
testSaga
(
getBookmarksForUserWatcher
)
.
next
()
.
next
()
.
takeEvery
(
GetBookmarksForUser
.
REQUEST
,
getBookmarkForUserWorker
)
.
takeEvery
(
GetBookmarksForUser
.
REQUEST
,
getBookmarkForUserWorker
);
.
next
().
isDone
(
);
});
});
});
});
...
@@ -296,10 +296,10 @@ describe('bookmark ducks', () => {
...
@@ -296,10 +296,10 @@ describe('bookmark ducks', () => {
action
=
getBookmarksForUser
(
testUserId
);
action
=
getBookmarksForUser
(
testUserId
);
});
});
it
(
'
adds a bookmark
'
,
()
=>
{
it
(
'
gets bookmarks
'
,
()
=>
{
return
expectSaga
(
getBookmarkForUserWorker
,
action
)
return
expectSaga
(
getBookmarkForUserWorker
,
action
)
.
provide
([
.
provide
([
[
matchers
.
call
.
fn
(
getBkm
rks
),
{
bookmarks
}],
[
matchers
.
call
.
fn
(
API
.
getBookma
rks
),
{
bookmarks
}],
])
])
.
put
(
getBookmarksForUserSuccess
(
bookmarks
))
.
put
(
getBookmarksForUserSuccess
(
bookmarks
))
.
run
();
.
run
();
...
@@ -308,7 +308,7 @@ describe('bookmark ducks', () => {
...
@@ -308,7 +308,7 @@ describe('bookmark ducks', () => {
it
(
'handles request error'
,
()
=>
{
it
(
'handles request error'
,
()
=>
{
return
expectSaga
(
getBookmarkForUserWorker
,
action
)
return
expectSaga
(
getBookmarkForUserWorker
,
action
)
.
provide
([
.
provide
([
[
matchers
.
call
.
fn
(
getBkm
rks
),
throwError
(
new
Error
())],
[
matchers
.
call
.
fn
(
API
.
getBookma
rks
),
throwError
(
new
Error
())],
])
])
.
put
(
getBookmarksForUserFailure
())
.
put
(
getBookmarksForUserFailure
())
.
run
();
.
run
();
...
@@ -318,8 +318,8 @@ describe('bookmark ducks', () => {
...
@@ -318,8 +318,8 @@ describe('bookmark ducks', () => {
describe
(
'removeBookmarkWatcher'
,
()
=>
{
describe
(
'removeBookmarkWatcher'
,
()
=>
{
it
(
'takes RemoveBookmark.REQUEST with removeBookmarkWorker'
,
()
=>
{
it
(
'takes RemoveBookmark.REQUEST with removeBookmarkWorker'
,
()
=>
{
testSaga
(
removeBookmarkWatcher
)
testSaga
(
removeBookmarkWatcher
)
.
next
()
.
next
()
.
takeEvery
(
RemoveBookmark
.
REQUEST
,
removeBookmarkWorker
)
.
takeEvery
(
RemoveBookmark
.
REQUEST
,
removeBookmarkWorker
);
.
next
().
isDone
(
);
});
});
});
});
...
@@ -332,7 +332,7 @@ describe('bookmark ducks', () => {
...
@@ -332,7 +332,7 @@ describe('bookmark ducks', () => {
it
(
'removes a bookmark'
,
()
=>
{
it
(
'removes a bookmark'
,
()
=>
{
return
expectSaga
(
removeBookmarkWorker
,
action
)
return
expectSaga
(
removeBookmarkWorker
,
action
)
.
provide
([
.
provide
([
[
matchers
.
call
.
fn
(
removeBkm
rk
),
{}],
[
matchers
.
call
.
fn
(
API
.
removeBookma
rk
),
{}],
])
])
.
put
(
removeBookmarkSuccess
(
testResourceKey
,
testResourceType
))
.
put
(
removeBookmarkSuccess
(
testResourceKey
,
testResourceType
))
.
run
();
.
run
();
...
@@ -341,7 +341,7 @@ describe('bookmark ducks', () => {
...
@@ -341,7 +341,7 @@ describe('bookmark ducks', () => {
it
(
'handles request error'
,
()
=>
{
it
(
'handles request error'
,
()
=>
{
return
expectSaga
(
removeBookmarkWorker
,
action
)
return
expectSaga
(
removeBookmarkWorker
,
action
)
.
provide
([
.
provide
([
[
matchers
.
call
.
fn
(
removeBkm
rk
),
throwError
(
new
Error
())],
[
matchers
.
call
.
fn
(
API
.
removeBookma
rk
),
throwError
(
new
Error
())],
])
])
.
put
(
removeBookmarkFailure
())
.
put
(
removeBookmarkFailure
())
.
run
();
.
run
();
...
...
amundsen_application/static/js/ducks/feedback/api/tests/index.spec.ts
View file @
32ab7c8b
import
axios
from
'axios'
;
import
axios
from
'axios'
;
import
{
feedbackSubmit
}
from
'../v0'
;
import
*
as
API
from
'../v0'
;
jest
.
mock
(
'axios'
);
jest
.
mock
(
'axios'
);
describe
(
'
feedbackSubmit
'
,
()
=>
{
describe
(
'
submitFeedback
'
,
()
=>
{
let
formData
:
FormData
;
let
formData
:
FormData
;
beforeAll
(()
=>
{
beforeAll
(()
=>
{
formData
=
new
FormData
();
formData
=
new
FormData
();
feedbackSubmit
(
formData
);
API
.
submitFeedback
(
formData
);
});
});
it
(
'calls axios with expected payload'
,
()
=>
{
it
(
'calls axios with expected payload'
,
()
=>
{
...
...
amundsen_application/static/js/ducks/feedback/api/v0.ts
View file @
32ab7c8b
import
axios
from
'axios'
;
import
axios
from
'axios'
;
export
function
feedbackSubmit
(
data
:
FormData
)
{
export
function
submitFeedback
(
data
:
FormData
)
{
return
axios
({
return
axios
({
data
,
data
,
method
:
'post'
,
method
:
'post'
,
...
...
amundsen_application/static/js/ducks/feedback/sagas.ts
View file @
32ab7c8b
import
{
SagaIterator
}
from
'redux-saga'
;
import
{
SagaIterator
}
from
'redux-saga'
;
import
{
call
,
delay
,
put
,
takeEvery
}
from
'redux-saga/effects'
;
import
{
call
,
delay
,
put
,
takeEvery
}
from
'redux-saga/effects'
;
import
{
feedbackSubmit
}
from
'./api/v0'
;
import
*
as
API
from
'./api/v0'
;
import
{
submitFeedbackFailure
,
submitFeedbackSuccess
,
resetFeedback
}
from
'./reducer'
;
import
{
submitFeedbackFailure
,
submitFeedbackSuccess
,
resetFeedback
}
from
'./reducer'
;
import
{
SubmitFeedback
,
SubmitFeedbackRequest
}
from
'./types'
;
import
{
SubmitFeedback
,
SubmitFeedbackRequest
}
from
'./types'
;
export
function
*
submitFeedbackWorker
(
action
:
SubmitFeedbackRequest
):
SagaIterator
{
export
function
*
submitFeedbackWorker
(
action
:
SubmitFeedbackRequest
):
SagaIterator
{
try
{
try
{
yield
call
(
feedbackSubmit
,
action
.
payload
.
data
);
yield
call
(
API
.
submitFeedback
,
action
.
payload
.
data
);
yield
put
(
submitFeedbackSuccess
());
yield
put
(
submitFeedbackSuccess
());
yield
delay
(
2000
);
yield
delay
(
2000
);
...
...
amundsen_application/static/js/ducks/feedback/tests/index.spec.ts
View file @
32ab7c8b
...
@@ -2,7 +2,7 @@ import { testSaga } from 'redux-saga-test-plan';
...
@@ -2,7 +2,7 @@ import { testSaga } from 'redux-saga-test-plan';
import
{
SendingState
}
from
'interfaces'
;
import
{
SendingState
}
from
'interfaces'
;
import
{
feedbackSubmit
}
from
'../api/v0'
;
import
*
as
API
from
'../api/v0'
;
import
reducer
,
{
import
reducer
,
{
submitFeedback
,
submitFeedback
,
submitFeedbackFailure
,
submitFeedbackFailure
,
...
@@ -87,37 +87,27 @@ describe('feedback ducks', () => {
...
@@ -87,37 +87,27 @@ describe('feedback ducks', () => {
describe
(
'submitFeedbackWatcher'
,
()
=>
{
describe
(
'submitFeedbackWatcher'
,
()
=>
{
it
(
'takes every SubmitFeedback.REQUEST with submitFeedbackWorker'
,
()
=>
{
it
(
'takes every SubmitFeedback.REQUEST with submitFeedbackWorker'
,
()
=>
{
testSaga
(
submitFeedbackWatcher
)
testSaga
(
submitFeedbackWatcher
)
.
next
()
.
next
()
.
takeEvery
(
SubmitFeedback
.
REQUEST
,
submitFeedbackWorker
)
.
takeEvery
(
SubmitFeedback
.
REQUEST
,
submitFeedbackWorker
);
.
next
().
isDone
(
);
});
});
});
});
describe
(
'submitFeedbackWorker'
,
()
=>
{
describe
(
'submitFeedbackWorker'
,
()
=>
{
it
(
'executes submit feedback flow'
,
()
=>
{
it
(
'executes submit feedback flow'
,
()
=>
{
testSaga
(
submitFeedbackWorker
,
action
)
testSaga
(
submitFeedbackWorker
,
action
)
.
next
()
.
next
().
call
(
API
.
submitFeedback
,
formData
)
.
call
(
feedbackSubmit
,
formData
)
.
next
().
put
(
submitFeedbackSuccess
())
.
next
()
.
next
().
delay
(
2000
)
.
put
(
submitFeedbackSuccess
())
.
next
().
put
(
resetFeedback
())
.
next
()
.
next
().
isDone
();
.
delay
(
2000
)
.
next
()
.
put
(
resetFeedback
())
.
next
()
.
isDone
();
});
});
it
(
'handles request error'
,
()
=>
{
it
(
'handles request error'
,
()
=>
{
testSaga
(
submitFeedbackWorker
,
action
)
testSaga
(
submitFeedbackWorker
,
action
)
.
next
()
.
next
().
throw
(
new
Error
()).
put
(
submitFeedbackFailure
())
.
throw
(
new
Error
())
.
next
().
delay
(
2000
)
.
put
(
submitFeedbackFailure
())
.
next
().
put
(
resetFeedback
())
.
next
()
.
next
().
isDone
();
.
delay
(
2000
)
.
next
()
.
put
(
resetFeedback
())
.
next
()
.
isDone
();
});
});
});
});
});
});
...
...
amundsen_application/static/js/ducks/log/api/tests/index.spec.ts
View file @
32ab7c8b
import
axios
from
'axios'
;
import
axios
from
'axios'
;
import
{
postActionLog
,
BASE_URL
,
ActionLogParams
}
from
'../v0'
;
import
*
as
API
from
'../v0'
;
jest
.
mock
(
'axios'
);
jest
.
mock
(
'axios'
);
describe
(
'postActionLog'
,
()
=>
{
describe
(
'postActionLog'
,
()
=>
{
let
axiosMock
;
let
axiosMock
;
let
params
:
ActionLogParams
;
let
params
:
A
PI
.
A
ctionLogParams
;
beforeAll
(()
=>
{
beforeAll
(()
=>
{
axiosMock
=
jest
.
spyOn
(
axios
,
'post'
).
mockImplementation
(()
=>
Promise
.
resolve
());
axiosMock
=
jest
.
spyOn
(
axios
,
'post'
).
mockImplementation
(()
=>
Promise
.
resolve
());
params
=
{};
params
=
{};
postActionLog
(
params
);
API
.
postActionLog
(
params
);
});
});
it
(
'calls axios with expected parameters'
,()
=>
{
it
(
'calls axios with expected parameters'
,()
=>
{
expect
(
axiosMock
).
toHaveBeenCalledWith
(
BASE_URL
,
params
);
expect
(
axiosMock
).
toHaveBeenCalledWith
(
API
.
BASE_URL
,
params
);
});
});
afterAll
(()
=>
{
afterAll
(()
=>
{
...
...
amundsen_application/static/js/ducks/popularTables/api/tests/index.spec.ts
View file @
32ab7c8b
...
@@ -4,14 +4,14 @@ import globalState from 'fixtures/globalState';
...
@@ -4,14 +4,14 @@ import globalState from 'fixtures/globalState';
import
{
TableResource
}
from
'interfaces'
;
import
{
TableResource
}
from
'interfaces'
;
import
{
metadataPopularTables
,
PopularTablesAPI
}
from
'../v0'
;
import
*
as
API
from
'../v0'
;
jest
.
mock
(
'axios'
);
jest
.
mock
(
'axios'
);
describe
(
'
metadata
PopularTables'
,
()
=>
{
describe
(
'
get
PopularTables'
,
()
=>
{
let
axiosMock
;
let
axiosMock
;
let
expectedTables
:
TableResource
[];
let
expectedTables
:
TableResource
[];
let
mockGetResponse
:
AxiosResponse
<
PopularTablesAPI
>
;
let
mockGetResponse
:
AxiosResponse
<
API
.
PopularTablesAPI
>
;
beforeAll
(()
=>
{
beforeAll
(()
=>
{
expectedTables
=
globalState
.
popularTables
;
expectedTables
=
globalState
.
popularTables
;
mockGetResponse
=
{
mockGetResponse
=
{
...
@@ -29,7 +29,7 @@ describe('metadataPopularTables', () => {
...
@@ -29,7 +29,7 @@ describe('metadataPopularTables', () => {
it
(
'resolves with array of table resources from response.data on success'
,
async
()
=>
{
it
(
'resolves with array of table resources from response.data on success'
,
async
()
=>
{
expect
.
assertions
(
1
);
expect
.
assertions
(
1
);
await
metadata
PopularTables
().
then
(
results
=>
{
await
API
.
get
PopularTables
().
then
(
results
=>
{
expect
(
results
).
toEqual
(
expectedTables
);
expect
(
results
).
toEqual
(
expectedTables
);
});
});
});
});
...
...
amundsen_application/static/js/ducks/popularTables/api/v0.ts
View file @
32ab7c8b
...
@@ -7,7 +7,7 @@ export type PopularTablesAPI = {
...
@@ -7,7 +7,7 @@ export type PopularTablesAPI = {
results
:
TableResource
[];
results
:
TableResource
[];
}
}
export
function
metadata
PopularTables
()
{
export
function
get
PopularTables
()
{
return
axios
.
get
(
'/api/metadata/v0/popular_tables'
)
return
axios
.
get
(
'/api/metadata/v0/popular_tables'
)
.
then
((
response
:
AxiosResponse
<
PopularTablesAPI
>
)
=>
{
.
then
((
response
:
AxiosResponse
<
PopularTablesAPI
>
)
=>
{
return
response
.
data
.
results
;
return
response
.
data
.
results
;
...
...
amundsen_application/static/js/ducks/popularTables/sagas.ts
View file @
32ab7c8b
import
{
SagaIterator
}
from
'redux-saga'
;
import
{
SagaIterator
}
from
'redux-saga'
;
import
{
call
,
put
,
takeEvery
}
from
'redux-saga/effects'
;
import
{
call
,
put
,
takeEvery
}
from
'redux-saga/effects'
;
import
{
metadataPopularTables
}
from
'./api/v0'
;
import
*
as
API
from
'./api/v0'
;
import
{
getPopularTablesFailure
,
getPopularTablesSuccess
}
from
'./reducer'
;
import
{
getPopularTablesFailure
,
getPopularTablesSuccess
}
from
'./reducer'
;
import
{
GetPopularTables
}
from
'./types'
;
import
{
GetPopularTables
}
from
'./types'
;
export
function
*
getPopularTablesWorker
():
SagaIterator
{
export
function
*
getPopularTablesWorker
():
SagaIterator
{
try
{
try
{
const
popularTables
=
yield
call
(
metadata
PopularTables
);
const
popularTables
=
yield
call
(
API
.
get
PopularTables
);
yield
put
(
getPopularTablesSuccess
(
popularTables
));
yield
put
(
getPopularTablesSuccess
(
popularTables
));
}
catch
(
e
)
{
}
catch
(
e
)
{
yield
put
(
getPopularTablesFailure
());
yield
put
(
getPopularTablesFailure
());
...
...
amundsen_application/static/js/ducks/popularTables/tests/index.spec.ts
View file @
32ab7c8b
...
@@ -4,7 +4,7 @@ import { TableResource } from 'interfaces';
...
@@ -4,7 +4,7 @@ import { TableResource } from 'interfaces';
import
globalState
from
'fixtures/globalState'
;
import
globalState
from
'fixtures/globalState'
;
import
{
metadataPopularTables
}
from
'../api/v0'
;
import
*
as
API
from
'../api/v0'
;
import
reducer
,
{
import
reducer
,
{
getPopularTables
,
getPopularTables
,
getPopularTablesFailure
,
getPopularTablesFailure
,
...
@@ -66,29 +66,23 @@ describe('popularTables ducks', () => {
...
@@ -66,29 +66,23 @@ describe('popularTables ducks', () => {
describe
(
'getPopularTablesWatcher'
,
()
=>
{
describe
(
'getPopularTablesWatcher'
,
()
=>
{
it
(
'takes every GetPopularTables.REQUEST with getPopularTablesWorker'
,
()
=>
{
it
(
'takes every GetPopularTables.REQUEST with getPopularTablesWorker'
,
()
=>
{
testSaga
(
getPopularTablesWatcher
)
testSaga
(
getPopularTablesWatcher
)
.
next
()
.
next
()
.
takeEvery
(
GetPopularTables
.
REQUEST
,
getPopularTablesWorker
)
.
takeEvery
(
GetPopularTables
.
REQUEST
,
getPopularTablesWorker
);
.
next
().
isDone
(
);
});
});
});
});
describe
(
'getPopularTablesWorker'
,
()
=>
{
describe
(
'getPopularTablesWorker'
,
()
=>
{
it
(
'executes flow for returning tables'
,
()
=>
{
it
(
'executes flow for returning tables'
,
()
=>
{
testSaga
(
getPopularTablesWorker
)
testSaga
(
getPopularTablesWorker
)
.
next
()
.
next
().
call
(
API
.
getPopularTables
)
.
call
(
metadataPopularTables
)
.
next
(
expectedTables
).
put
(
getPopularTablesSuccess
(
expectedTables
))
.
next
(
expectedTables
)
.
next
().
isDone
();
.
put
(
getPopularTablesSuccess
(
expectedTables
))
.
next
()
.
isDone
();
});
});
it
(
'handles request error'
,
()
=>
{
it
(
'handles request error'
,
()
=>
{
testSaga
(
getPopularTablesWorker
)
testSaga
(
getPopularTablesWorker
)
.
next
()
.
next
().
throw
(
new
Error
()).
put
(
getPopularTablesFailure
())
.
throw
(
new
Error
())
.
next
().
isDone
();
.
put
(
getPopularTablesFailure
())
.
next
()
.
isDone
();
});
});
});
});
});
});
...
...
amundsen_application/static/js/ducks/search/api/tests/index.spec.ts
View file @
32ab7c8b
import
axios
,
{
AxiosResponse
}
from
'axios'
;
import
axios
,
{
AxiosResponse
}
from
'axios'
;
import
AppConfig
from
'config/config'
;
import
{
DashboardSearchResults
,
TableSearchResults
,
UserSearchResults
}
from
'ducks/search/types'
;
import
{
DashboardSearchResults
,
TableSearchResults
,
UserSearchResults
}
from
'ducks/search/types'
;
import
globalState
from
'fixtures/globalState'
;
import
globalState
from
'fixtures/globalState'
;
import
{
ResourceType
,
SearchAllOptions
}
from
'interfaces'
;
import
{
ResourceType
,
SearchAllOptions
}
from
'interfaces'
;
import
{
searchResource
,
searchResourceHelper
,
SearchAPI
,
BASE_URL
}
from
'../v0'
;
import
*
as
API
from
'../v0'
;
jest
.
mock
(
'axios'
);
jest
.
mock
(
'axios'
);
describe
(
'searchResource'
,
()
=>
{
describe
(
'searchResource'
,
()
=>
{
let
axiosMockGet
;
let
axiosMockGet
;
let
mockTableResponse
:
AxiosResponse
<
SearchAPI
>
;
let
mockTableResponse
:
AxiosResponse
<
API
.
SearchAPI
>
;
beforeAll
(()
=>
{
beforeAll
(()
=>
{
mockTableResponse
=
{
mockTableResponse
=
{
data
:
{
data
:
{
...
@@ -30,25 +34,51 @@ describe('searchResource', () => {
...
@@ -30,25 +34,51 @@ describe('searchResource', () => {
axiosMockGet
=
jest
.
spyOn
(
axios
,
'get'
).
mockImplementation
(()
=>
Promise
.
resolve
(
mockTableResponse
));
axiosMockGet
=
jest
.
spyOn
(
axios
,
'get'
).
mockImplementation
(()
=>
Promise
.
resolve
(
mockTableResponse
));
});
});
describe
(
'searchResource'
,
()
=>
{
it
(
'calls axios get with request for a resource'
,
async
()
=>
{
it
(
'calls axios get with request for a resource'
,
async
()
=>
{
axiosMockGet
.
mockClear
();
const
pageIndex
=
0
;
const
pageIndex
=
0
;
const
resourceType
=
ResourceType
.
table
;
const
resourceType
=
ResourceType
.
table
;
const
term
=
'test'
;
const
term
=
'test'
;
await
searchResource
(
pageIndex
,
resourceType
,
term
);
await
API
.
searchResource
(
pageIndex
,
resourceType
,
term
);
expect
(
axiosMockGet
).
toHaveBeenCalledWith
(
`
${
BASE_URL
}
/
${
resourceType
}
?query=
${
term
}
&page_index=
${
pageIndex
}
`
);
expect
(
axiosMockGet
).
toHaveBeenCalledWith
(
`
${
API
.
BASE_URL
}
/
${
resourceType
}
?query=
${
term
}
&page_index=
${
pageIndex
}
`
);
});
it
(
'calls searchResourceHelper with api call response'
,
async
()
=>
{
const
searchResourceHelperSpy
=
jest
.
spyOn
(
API
,
'searchResourceHelper'
);
await
API
.
searchResource
(
0
,
ResourceType
.
table
,
'test'
);
expect
(
searchResourceHelperSpy
).
toHaveBeenCalledWith
(
mockTableResponse
);
});
it
(
'resolves with empty object if dashboard resource search not supported'
,
async
()
=>
{
axiosMockGet
.
mockClear
();
const
pageIndex
=
0
;
const
resourceType
=
ResourceType
.
dashboard
;
const
term
=
'test'
;
expect
.
assertions
(
2
);
await
API
.
searchResource
(
pageIndex
,
resourceType
,
term
).
then
(
results
=>
{
expect
(
results
).
toEqual
({});
});
expect
(
axiosMockGet
).
not
.
toHaveBeenCalled
();
});
});
/*
it
(
'resolves with empty object if user resource search not supported'
,
async
()
=>
{
TODO: Not set up to test this.
axiosMockGet
.
mockClear
();
it('calls searchResourceHelper with resolved results', async () => {
AppConfig
.
indexUsers
.
enabled
=
false
;
await searchResource(0, ResourceType.table, 'test');
const
pageIndex
=
0
;
expect(searchResourceHelper).toHaveBeenCalledWith(mockTableResponse);
const
resourceType
=
ResourceType
.
user
;
const
term
=
'test'
;
expect
.
assertions
(
2
);
await
API
.
searchResource
(
pageIndex
,
resourceType
,
term
).
then
(
results
=>
{
expect
(
results
).
toEqual
({});
});
expect
(
axiosMockGet
).
not
.
toHaveBeenCalled
();
});
});
});
*/
describe
(
'searchResourceHelper'
,
()
=>
{
describe
(
'searchResourceHelper'
,
()
=>
{
it
(
'returns expected object'
,
()
=>
{
it
(
'returns expected object'
,
()
=>
{
expect
(
searchResourceHelper
(
mockTableResponse
)).
toEqual
({
expect
(
API
.
searchResourceHelper
(
mockTableResponse
)).
toEqual
({
searchTerm
:
mockTableResponse
.
data
.
search_term
,
searchTerm
:
mockTableResponse
.
data
.
search_term
,
tables
:
mockTableResponse
.
data
.
tables
,
tables
:
mockTableResponse
.
data
.
tables
,
users
:
mockTableResponse
.
data
.
users
,
users
:
mockTableResponse
.
data
.
users
,
...
...
amundsen_application/static/js/ducks/search/sagas.ts
View file @
32ab7c8b
...
@@ -3,6 +3,8 @@ import { all, call, put, takeEvery } from 'redux-saga/effects';
...
@@ -3,6 +3,8 @@ import { all, call, put, takeEvery } from 'redux-saga/effects';
import
{
ResourceType
}
from
'interfaces/Resources'
;
import
{
ResourceType
}
from
'interfaces/Resources'
;
import
*
as
API
from
'./api/v0'
;
import
{
import
{
SearchAll
,
SearchAll
,
SearchAllRequest
,
SearchAllRequest
,
...
@@ -10,10 +12,6 @@ import {
...
@@ -10,10 +12,6 @@ import {
SearchResourceRequest
,
SearchResourceRequest
,
}
from
'./types'
;
}
from
'./types'
;
import
{
searchResource
,
}
from
'./api/v0'
;
import
{
import
{
searchAllSuccess
,
searchAllFailure
,
searchAllSuccess
,
searchAllFailure
,
searchResourceSuccess
,
searchResourceFailure
,
searchResourceSuccess
,
searchResourceFailure
,
...
@@ -23,9 +21,9 @@ export function* searchAllWorker(action: SearchAllRequest): SagaIterator {
...
@@ -23,9 +21,9 @@ export function* searchAllWorker(action: SearchAllRequest): SagaIterator {
const
{
options
,
term
}
=
action
.
payload
;
const
{
options
,
term
}
=
action
.
payload
;
try
{
try
{
const
[
tableResponse
,
userResponse
,
dashboardResponse
]
=
yield
all
([
const
[
tableResponse
,
userResponse
,
dashboardResponse
]
=
yield
all
([
call
(
searchResource
,
options
.
tableIndex
,
ResourceType
.
table
,
term
),
call
(
API
.
searchResource
,
options
.
tableIndex
,
ResourceType
.
table
,
term
),
call
(
searchResource
,
options
.
userIndex
,
ResourceType
.
user
,
term
),
call
(
API
.
searchResource
,
options
.
userIndex
,
ResourceType
.
user
,
term
),
call
(
searchResource
,
options
.
dashboardIndex
,
ResourceType
.
dashboard
,
term
),
call
(
API
.
searchResource
,
options
.
dashboardIndex
,
ResourceType
.
dashboard
,
term
),
]);
]);
const
searchAllResponse
=
{
const
searchAllResponse
=
{
search_term
:
term
,
search_term
:
term
,
...
@@ -45,7 +43,7 @@ export function* searchAllWatcher(): SagaIterator {
...
@@ -45,7 +43,7 @@ export function* searchAllWatcher(): SagaIterator {
export
function
*
searchResourceWorker
(
action
:
SearchResourceRequest
):
SagaIterator
{
export
function
*
searchResourceWorker
(
action
:
SearchResourceRequest
):
SagaIterator
{
const
{
pageIndex
,
resource
,
term
}
=
action
.
payload
;
const
{
pageIndex
,
resource
,
term
}
=
action
.
payload
;
try
{
try
{
const
searchResults
=
yield
call
(
searchResource
,
pageIndex
,
resource
,
term
);
const
searchResults
=
yield
call
(
API
.
searchResource
,
pageIndex
,
resource
,
term
);
yield
put
(
searchResourceSuccess
(
searchResults
));
yield
put
(
searchResourceSuccess
(
searchResults
));
}
catch
(
e
)
{
}
catch
(
e
)
{
yield
put
(
searchResourceFailure
());
yield
put
(
searchResourceFailure
());
...
...
amundsen_application/static/js/ducks/search/tests/index.spec.ts
View file @
32ab7c8b
...
@@ -4,7 +4,7 @@ import { ResourceType } from 'interfaces';
...
@@ -4,7 +4,7 @@ import { ResourceType } from 'interfaces';
import
globalState
from
'fixtures/globalState'
;
import
globalState
from
'fixtures/globalState'
;
import
{
searchResource
as
srchResource
}
from
'../api/v0'
;
import
*
as
API
from
'../api/v0'
;
import
reducer
,
{
import
reducer
,
{
searchAll
,
searchAllSuccess
,
searchAllFailure
,
searchAll
,
searchAllSuccess
,
searchAllFailure
,
...
@@ -146,8 +146,8 @@ describe('search ducks', () => {
...
@@ -146,8 +146,8 @@ describe('search ducks', () => {
describe
(
'searchAllWatcher'
,
()
=>
{
describe
(
'searchAllWatcher'
,
()
=>
{
it
(
'takes every SearchAll.REQUEST with searchAllWorker'
,
()
=>
{
it
(
'takes every SearchAll.REQUEST with searchAllWorker'
,
()
=>
{
testSaga
(
searchAllWatcher
)
testSaga
(
searchAllWatcher
)
.
next
()
.
next
()
.
takeEvery
(
SearchAll
.
REQUEST
,
searchAllWorker
)
.
takeEvery
(
SearchAll
.
REQUEST
,
searchAllWorker
);
.
next
().
isDone
(
);
});
});
});
});
...
@@ -167,19 +167,16 @@ describe('search ducks', () => {
...
@@ -167,19 +167,16 @@ describe('search ducks', () => {
it
(
'handles request error'
,
()
=>
{
it
(
'handles request error'
,
()
=>
{
testSaga
(
searchAllWorker
,
searchAll
(
'test'
,
{}))
testSaga
(
searchAllWorker
,
searchAll
(
'test'
,
{}))
.
next
()
.
next
().
throw
(
new
Error
()).
put
(
searchAllFailure
())
.
throw
(
new
Error
())
.
next
().
isDone
();
.
put
(
searchAllFailure
())
.
next
()
.
isDone
();
});
});
});
});
describe
(
'searchResourceWatcher'
,
()
=>
{
describe
(
'searchResourceWatcher'
,
()
=>
{
it
(
'takes every SearchResource.REQUEST with searchResourceWorker'
,
()
=>
{
it
(
'takes every SearchResource.REQUEST with searchResourceWorker'
,
()
=>
{
testSaga
(
searchResourceWatcher
)
testSaga
(
searchResourceWatcher
)
.
next
()
.
next
()
.
takeEvery
(
SearchResource
.
REQUEST
,
searchResourceWorker
)
.
takeEvery
(
SearchResource
.
REQUEST
,
searchResourceWorker
);
.
next
().
isDone
(
);
});
});
});
});
...
@@ -189,21 +186,15 @@ describe('search ducks', () => {
...
@@ -189,21 +186,15 @@ describe('search ducks', () => {
const
resource
=
ResourceType
.
table
;
const
resource
=
ResourceType
.
table
;
const
term
=
'test'
;
const
term
=
'test'
;
testSaga
(
searchResourceWorker
,
searchResource
(
resource
,
term
,
pageIndex
))
testSaga
(
searchResourceWorker
,
searchResource
(
resource
,
term
,
pageIndex
))
.
next
()
.
next
().
call
(
API
.
searchResource
,
pageIndex
,
resource
,
term
)
.
call
(
srchResource
,
pageIndex
,
resource
,
term
)
.
next
(
expectedSearchResults
).
put
(
searchResourceSuccess
(
expectedSearchResults
))
.
next
(
expectedSearchResults
)
.
next
().
isDone
();
.
put
(
searchResourceSuccess
(
expectedSearchResults
))
.
next
()
.
isDone
();
});
});
it
(
'handles request error'
,
()
=>
{
it
(
'handles request error'
,
()
=>
{
testSaga
(
searchResourceWorker
,
searchResource
(
ResourceType
.
table
,
'test'
,
0
))
testSaga
(
searchResourceWorker
,
searchResource
(
ResourceType
.
table
,
'test'
,
0
))
.
next
()
.
next
().
throw
(
new
Error
()).
put
(
searchResourceFailure
())
.
throw
(
new
Error
())
.
next
().
isDone
();
.
put
(
searchResourceFailure
())
.
next
()
.
isDone
();
});
});
});
});
});
});
...
...
amundsen_application/static/js/ducks/tableMetadata/api/helpers.ts
View file @
32ab7c8b
import
{
filterFromObj
,
sortTagsAlphabetical
}
from
'ducks/utilMethods'
;
import
{
filterFromObj
,
sortTagsAlphabetical
}
from
'ducks/utilMethods'
;
import
{
OwnerDict
,
TableMetadata
,
Tag
,
User
}
from
'interfaces'
;
import
{
OwnerDict
,
TableMetadata
,
Tag
,
User
}
from
'interfaces'
;
import
{
TableDataAPI
}
from
'./v0'
;
import
*
as
API
from
'./v0'
;
/**
/**
* Generates the query string parameters needed for requests that act on a particular table resource.
* Generates the query string parameters needed for requests that act on a particular table resource.
...
@@ -13,14 +13,14 @@ export function getTableQueryParams(tableKey: string): string {
...
@@ -13,14 +13,14 @@ export function getTableQueryParams(tableKey: string): string {
/**
/**
* Parses the response for table metadata to create a TableMetadata object
* Parses the response for table metadata to create a TableMetadata object
*/
*/
export
function
getTableDataFromResponseData
(
responseData
:
TableDataAPI
):
TableMetadata
{
export
function
getTableDataFromResponseData
(
responseData
:
API
.
TableDataAPI
):
TableMetadata
{
return
filterFromObj
(
responseData
.
tableData
,
[
'owners'
,
'tags'
])
as
TableMetadata
;
return
filterFromObj
(
responseData
.
tableData
,
[
'owners'
,
'tags'
])
as
TableMetadata
;
}
}
/**
/**
* Parses the response for table metadata to return the array of table owners
* Parses the response for table metadata to return the array of table owners
*/
*/
export
function
getTableOwnersFromResponseData
(
responseData
:
TableDataAPI
):
OwnerDict
{
export
function
getTableOwnersFromResponseData
(
responseData
:
API
.
TableDataAPI
):
OwnerDict
{
// TODO: owner needs proper id, until then we have to remember that we are using display_name
// TODO: owner needs proper id, until then we have to remember that we are using display_name
const
ownerObj
=
responseData
.
tableData
.
owners
.
reduce
((
resultObj
,
currentOwner
)
=>
{
const
ownerObj
=
responseData
.
tableData
.
owners
.
reduce
((
resultObj
,
currentOwner
)
=>
{
resultObj
[
currentOwner
.
display_name
]
=
currentOwner
as
User
;
resultObj
[
currentOwner
.
display_name
]
=
currentOwner
as
User
;
...
@@ -32,6 +32,6 @@ export function getTableOwnersFromResponseData(responseData: TableDataAPI): Owne
...
@@ -32,6 +32,6 @@ export function getTableOwnersFromResponseData(responseData: TableDataAPI): Owne
/**
/**
* Parses the response for table metadata to return an array of sorted table tags
* Parses the response for table metadata to return an array of sorted table tags
*/
*/
export
function
getTableTagsFromResponseData
(
responseData
:
TableDataAPI
):
Tag
[]
{
export
function
getTableTagsFromResponseData
(
responseData
:
API
.
TableDataAPI
):
Tag
[]
{
return
responseData
.
tableData
.
tags
.
sort
(
sortTagsAlphabetical
);
return
responseData
.
tableData
.
tags
.
sort
(
sortTagsAlphabetical
);
}
}
amundsen_application/static/js/ducks/tableMetadata/api/tests/index.spec.ts
View file @
32ab7c8b
...
@@ -6,15 +6,15 @@ import * as Utils from 'ducks/utilMethods';
...
@@ -6,15 +6,15 @@ import * as Utils from 'ducks/utilMethods';
import
globalState
from
'fixtures/globalState'
;
import
globalState
from
'fixtures/globalState'
;
import
{
TableData
,
TableDataAPI
}
from
'../v0'
;
import
*
as
API
from
'../v0'
;
const
filterFromObjSpy
=
jest
.
spyOn
(
Utils
,
'filterFromObj'
).
mockImplementation
(()
=>
{});
const
filterFromObjSpy
=
jest
.
spyOn
(
Utils
,
'filterFromObj'
).
mockImplementation
(()
=>
{});
jest
.
mock
(
'axios'
);
jest
.
mock
(
'axios'
);
describe
(
'helpers'
,
()
=>
{
describe
(
'helpers'
,
()
=>
{
let
mockResponseData
:
TableDataAPI
;
let
mockResponseData
:
API
.
TableDataAPI
;
let
tableResponseData
:
TableData
;
let
tableResponseData
:
API
.
TableData
;
beforeAll
(()
=>
{
beforeAll
(()
=>
{
tableResponseData
=
{
tableResponseData
=
{
...
globalState
.
tableMetadata
.
tableData
,
...
globalState
.
tableMetadata
.
tableData
,
...
...
amundsen_application/static/js/ducks/tableMetadata/api/v0.ts
View file @
32ab7c8b
...
@@ -25,7 +25,7 @@ import {
...
@@ -25,7 +25,7 @@ import {
getTableQueryParams
,
getTableDataFromResponseData
,
getTableOwnersFromResponseData
,
getTableTagsFromResponseData
,
getTableQueryParams
,
getTableDataFromResponseData
,
getTableOwnersFromResponseData
,
getTableTagsFromResponseData
,
}
from
'./helpers'
;
}
from
'./helpers'
;
export
function
metadata
TableTags
(
tableKey
:
string
)
{
export
function
get
TableTags
(
tableKey
:
string
)
{
const
tableParams
=
getTableQueryParams
(
tableKey
);
const
tableParams
=
getTableQueryParams
(
tableKey
);
return
axios
.
get
(
`
${
API_PATH
}
/table?
${
tableParams
}
&index=&source=`
)
return
axios
.
get
(
`
${
API_PATH
}
/table?
${
tableParams
}
&index=&source=`
)
.
then
((
response
:
AxiosResponse
<
TableDataAPI
>
)
=>
{
.
then
((
response
:
AxiosResponse
<
TableDataAPI
>
)
=>
{
...
@@ -34,7 +34,7 @@ export function metadataTableTags(tableKey: string) {
...
@@ -34,7 +34,7 @@ export function metadataTableTags(tableKey: string) {
}
}
/* TODO: Typing this method generates redux-saga related type errors that needs more dedicated debugging */
/* TODO: Typing this method generates redux-saga related type errors that needs more dedicated debugging */
export
function
metadataU
pdateTableTags
(
tagArray
,
tableKey
:
string
)
{
export
function
u
pdateTableTags
(
tagArray
,
tableKey
:
string
)
{
const
updatePayloads
=
tagArray
.
map
((
tagObject
)
=>
{
const
updatePayloads
=
tagArray
.
map
((
tagObject
)
=>
{
return
{
return
{
method
:
tagObject
.
methodName
,
method
:
tagObject
.
methodName
,
...
@@ -48,7 +48,7 @@ export function metadataUpdateTableTags(tagArray, tableKey: string) {
...
@@ -48,7 +48,7 @@ export function metadataUpdateTableTags(tagArray, tableKey: string) {
return
updatePayloads
.
map
(
payload
=>
{
axios
(
payload
)
});
return
updatePayloads
.
map
(
payload
=>
{
axios
(
payload
)
});
}
}
export
function
metadataG
etTableData
(
tableKey
:
string
,
searchIndex
:
string
,
source
:
string
)
{
export
function
g
etTableData
(
tableKey
:
string
,
searchIndex
:
string
,
source
:
string
)
{
const
tableParams
=
getTableQueryParams
(
tableKey
);
const
tableParams
=
getTableQueryParams
(
tableKey
);
return
axios
.
get
(
`
${
API_PATH
}
/table?
${
tableParams
}
&index=
${
searchIndex
}
&source=
${
source
}
`
)
return
axios
.
get
(
`
${
API_PATH
}
/table?
${
tableParams
}
&index=
${
searchIndex
}
&source=
${
source
}
`
)
.
then
((
response
:
AxiosResponse
<
TableDataAPI
>
)
=>
{
.
then
((
response
:
AxiosResponse
<
TableDataAPI
>
)
=>
{
...
@@ -61,7 +61,7 @@ export function metadataGetTableData(tableKey: string, searchIndex: string, sour
...
@@ -61,7 +61,7 @@ export function metadataGetTableData(tableKey: string, searchIndex: string, sour
});
});
}
}
export
function
metadataG
etTableDescription
(
tableData
:
TableMetadata
)
{
export
function
g
etTableDescription
(
tableData
:
TableMetadata
)
{
const
tableParams
=
getTableQueryParams
(
tableData
.
key
);
const
tableParams
=
getTableQueryParams
(
tableData
.
key
);
return
axios
.
get
(
`
${
API_PATH
}
/v0/get_table_description?
${
tableParams
}
`
)
return
axios
.
get
(
`
${
API_PATH
}
/v0/get_table_description?
${
tableParams
}
`
)
.
then
((
response
:
AxiosResponse
<
DescriptionAPI
>
)
=>
{
.
then
((
response
:
AxiosResponse
<
DescriptionAPI
>
)
=>
{
...
@@ -70,7 +70,7 @@ export function metadataGetTableDescription(tableData: TableMetadata) {
...
@@ -70,7 +70,7 @@ export function metadataGetTableDescription(tableData: TableMetadata) {
});
});
}
}
export
function
metadataU
pdateTableDescription
(
description
:
string
,
tableData
:
TableMetadata
)
{
export
function
u
pdateTableDescription
(
description
:
string
,
tableData
:
TableMetadata
)
{
if
(
description
.
length
===
0
)
{
if
(
description
.
length
===
0
)
{
throw
new
Error
();
throw
new
Error
();
}
}
...
@@ -83,7 +83,7 @@ export function metadataUpdateTableDescription(description: string, tableData: T
...
@@ -83,7 +83,7 @@ export function metadataUpdateTableDescription(description: string, tableData: T
}
}
}
}
export
function
metadata
TableOwners
(
tableKey
:
string
)
{
export
function
get
TableOwners
(
tableKey
:
string
)
{
const
tableParams
=
getTableQueryParams
(
tableKey
);
const
tableParams
=
getTableQueryParams
(
tableKey
);
return
axios
.
get
(
`
${
API_PATH
}
/table?
${
tableParams
}
&index=&source=`
)
return
axios
.
get
(
`
${
API_PATH
}
/table?
${
tableParams
}
&index=&source=`
)
.
then
((
response
:
AxiosResponse
<
TableDataAPI
>
)
=>
{
.
then
((
response
:
AxiosResponse
<
TableDataAPI
>
)
=>
{
...
@@ -92,7 +92,7 @@ export function metadataTableOwners(tableKey: string) {
...
@@ -92,7 +92,7 @@ export function metadataTableOwners(tableKey: string) {
}
}
/* TODO: Typing this method generates redux-saga related type errors that need more dedicated debugging */
/* TODO: Typing this method generates redux-saga related type errors that need more dedicated debugging */
export
function
metadataU
pdateTableOwner
(
updateArray
,
tableKey
:
string
)
{
export
function
u
pdateTableOwner
(
updateArray
,
tableKey
:
string
)
{
const
updatePayloads
=
updateArray
.
map
((
item
)
=>
{
const
updatePayloads
=
updateArray
.
map
((
item
)
=>
{
return
{
return
{
method
:
item
.
method
,
method
:
item
.
method
,
...
@@ -106,7 +106,7 @@ export function metadataUpdateTableOwner(updateArray, tableKey: string) {
...
@@ -106,7 +106,7 @@ export function metadataUpdateTableOwner(updateArray, tableKey: string) {
return
updatePayloads
.
map
(
payload
=>
{
axios
(
payload
)
});
return
updatePayloads
.
map
(
payload
=>
{
axios
(
payload
)
});
}
}
export
function
metadataG
etColumnDescription
(
columnIndex
:
number
,
tableData
:
TableMetadata
)
{
export
function
g
etColumnDescription
(
columnIndex
:
number
,
tableData
:
TableMetadata
)
{
const
tableParams
=
getTableQueryParams
(
tableData
.
key
);
const
tableParams
=
getTableQueryParams
(
tableData
.
key
);
const
columnName
=
tableData
.
columns
[
columnIndex
].
name
;
const
columnName
=
tableData
.
columns
[
columnIndex
].
name
;
return
axios
.
get
(
`
${
API_PATH
}
/get_column_description?
${
tableParams
}
&column_name=
${
columnName
}
`
)
return
axios
.
get
(
`
${
API_PATH
}
/get_column_description?
${
tableParams
}
&column_name=
${
columnName
}
`
)
...
@@ -116,7 +116,7 @@ export function metadataGetColumnDescription(columnIndex: number, tableData: Tab
...
@@ -116,7 +116,7 @@ export function metadataGetColumnDescription(columnIndex: number, tableData: Tab
});
});
}
}
export
function
metadataU
pdateColumnDescription
(
description
:
string
,
columnIndex
:
number
,
tableData
:
TableMetadata
)
{
export
function
u
pdateColumnDescription
(
description
:
string
,
columnIndex
:
number
,
tableData
:
TableMetadata
)
{
if
(
description
.
length
===
0
)
{
if
(
description
.
length
===
0
)
{
throw
new
Error
();
throw
new
Error
();
}
}
...
@@ -131,14 +131,14 @@ export function metadataUpdateColumnDescription(description: string, columnIndex
...
@@ -131,14 +131,14 @@ export function metadataUpdateColumnDescription(description: string, columnIndex
}
}
}
}
export
function
metadataG
etLastIndexed
()
{
export
function
g
etLastIndexed
()
{
return
axios
.
get
(
`
${
API_PATH
}
/get_last_indexed`
)
return
axios
.
get
(
`
${
API_PATH
}
/get_last_indexed`
)
.
then
((
response
:
AxiosResponse
<
LastIndexedAPI
>
)
=>
{
.
then
((
response
:
AxiosResponse
<
LastIndexedAPI
>
)
=>
{
return
response
.
data
.
timestamp
;
return
response
.
data
.
timestamp
;
});
});
}
}
export
function
metadataG
etPreviewData
(
queryParams
:
PreviewQueryParams
)
{
export
function
g
etPreviewData
(
queryParams
:
PreviewQueryParams
)
{
return
axios
({
return
axios
({
url
:
'/api/preview/v0/'
,
url
:
'/api/preview/v0/'
,
method
:
'POST'
,
method
:
'POST'
,
...
...
amundsen_application/static/js/ducks/tableMetadata/owners/sagas.ts
View file @
32ab7c8b
import
{
SagaIterator
}
from
'redux-saga'
;
import
{
SagaIterator
}
from
'redux-saga'
;
import
{
all
,
call
,
put
,
select
,
takeEvery
}
from
'redux-saga/effects'
;
import
{
all
,
call
,
put
,
select
,
takeEvery
}
from
'redux-saga/effects'
;
import
{
metadataUpdateTableOwner
,
metadataTableOwners
}
from
'../api/v0'
;
import
*
as
API
from
'../api/v0'
;
import
{
updateTableOwnerFailure
,
updateTableOwnerSuccess
}
from
'./reducer'
;
import
{
updateTableOwnerFailure
,
updateTableOwnerSuccess
}
from
'./reducer'
;
...
@@ -12,8 +12,8 @@ export function* updateTableOwnerWorker(action: UpdateTableOwnerRequest): SagaIt
...
@@ -12,8 +12,8 @@ export function* updateTableOwnerWorker(action: UpdateTableOwnerRequest): SagaIt
const
state
=
yield
select
();
const
state
=
yield
select
();
const
tableData
=
state
.
tableMetadata
.
tableData
;
const
tableData
=
state
.
tableMetadata
.
tableData
;
try
{
try
{
yield
all
(
metadataU
pdateTableOwner
(
payload
.
updateArray
,
tableData
.
key
));
yield
all
(
API
.
u
pdateTableOwner
(
payload
.
updateArray
,
tableData
.
key
));
const
newOwners
=
yield
call
(
metadata
TableOwners
,
tableData
.
key
);
const
newOwners
=
yield
call
(
API
.
get
TableOwners
,
tableData
.
key
);
yield
put
(
updateTableOwnerSuccess
(
newOwners
));
yield
put
(
updateTableOwnerSuccess
(
newOwners
));
if
(
payload
.
onSuccess
)
{
if
(
payload
.
onSuccess
)
{
yield
call
(
payload
.
onSuccess
);
yield
call
(
payload
.
onSuccess
);
...
...
amundsen_application/static/js/ducks/tableMetadata/owners/tests/index.spec.ts
View file @
32ab7c8b
...
@@ -4,7 +4,7 @@ import { OwnerDict, UpdateMethod, UpdateOwnerPayload } from 'interfaces';
...
@@ -4,7 +4,7 @@ import { OwnerDict, UpdateMethod, UpdateOwnerPayload } from 'interfaces';
import
globalState
from
'fixtures/globalState'
;
import
globalState
from
'fixtures/globalState'
;
import
*
as
apis
from
'../../api/v0'
;
import
*
as
API
from
'../../api/v0'
;
import
reducer
,
{
import
reducer
,
{
updateTableOwner
,
updateTableOwnerFailure
,
updateTableOwnerSuccess
,
updateTableOwner
,
updateTableOwnerFailure
,
updateTableOwnerSuccess
,
...
@@ -16,7 +16,7 @@ import { updateTableOwnerWorker, updateTableOwnerWatcher } from '../sagas';
...
@@ -16,7 +16,7 @@ import { updateTableOwnerWorker, updateTableOwnerWatcher } from '../sagas';
import
{
GetTableData
,
UpdateTableOwner
}
from
'../../types'
;
import
{
GetTableData
,
UpdateTableOwner
}
from
'../../types'
;
const
metadataUpdateTableOwnerSpy
=
jest
.
spyOn
(
apis
,
'metadataU
pdateTableOwner'
).
mockImplementation
((
payload
,
key
)
=>
[]);
const
updateTableOwnerSpy
=
jest
.
spyOn
(
API
,
'u
pdateTableOwner'
).
mockImplementation
((
payload
,
key
)
=>
[]);
describe
(
'tableMetadata:owners ducks'
,
()
=>
{
describe
(
'tableMetadata:owners ducks'
,
()
=>
{
let
expectedOwners
:
OwnerDict
;
let
expectedOwners
:
OwnerDict
;
...
@@ -131,8 +131,8 @@ describe('tableMetadata:owners ducks', () => {
...
@@ -131,8 +131,8 @@ describe('tableMetadata:owners ducks', () => {
sagaTest
=
(
action
)
=>
{
sagaTest
=
(
action
)
=>
{
return
testSaga
(
updateTableOwnerWorker
,
action
)
return
testSaga
(
updateTableOwnerWorker
,
action
)
.
next
().
select
()
.
next
().
select
()
.
next
(
globalState
).
all
(
apis
.
metadataU
pdateTableOwner
(
updatePayload
,
globalState
.
tableMetadata
.
tableData
.
key
))
.
next
(
globalState
).
all
(
API
.
u
pdateTableOwner
(
updatePayload
,
globalState
.
tableMetadata
.
tableData
.
key
))
.
next
().
call
(
apis
.
metadata
TableOwners
,
globalState
.
tableMetadata
.
tableData
.
key
)
.
next
().
call
(
API
.
get
TableOwners
,
globalState
.
tableMetadata
.
tableData
.
key
)
.
next
(
expectedOwners
).
put
(
updateTableOwnerSuccess
(
expectedOwners
));
.
next
(
expectedOwners
).
put
(
updateTableOwnerSuccess
(
expectedOwners
));
};
};
});
});
...
...
amundsen_application/static/js/ducks/tableMetadata/sagas.ts
View file @
32ab7c8b
import
{
SagaIterator
}
from
'redux-saga'
;
import
{
SagaIterator
}
from
'redux-saga'
;
import
{
all
,
call
,
put
,
select
,
takeEvery
}
from
'redux-saga/effects'
;
import
{
all
,
call
,
put
,
select
,
takeEvery
}
from
'redux-saga/effects'
;
import
{
import
*
as
API
from
'./api/v0'
;
metadataGetLastIndexed
,
metadataGetPreviewData
,
metadataGetTableData
,
metadataGetColumnDescription
,
metadataGetTableDescription
,
metadataUpdateColumnDescription
,
metadataUpdateTableDescription
,
}
from
'./api/v0'
;
import
{
import
{
getTableDataFailure
,
getTableDataSuccess
,
getTableDataFailure
,
getTableDataSuccess
,
...
@@ -32,7 +24,7 @@ import {
...
@@ -32,7 +24,7 @@ import {
export
function
*
getTableDataWorker
(
action
:
GetTableDataRequest
):
SagaIterator
{
export
function
*
getTableDataWorker
(
action
:
GetTableDataRequest
):
SagaIterator
{
try
{
try
{
const
{
key
,
searchIndex
,
source
}
=
action
.
payload
;
const
{
key
,
searchIndex
,
source
}
=
action
.
payload
;
const
{
data
,
owners
,
statusCode
,
tags
}
=
yield
call
(
metadataG
etTableData
,
key
,
searchIndex
,
source
);
const
{
data
,
owners
,
statusCode
,
tags
}
=
yield
call
(
API
.
g
etTableData
,
key
,
searchIndex
,
source
);
yield
put
(
getTableDataSuccess
(
data
,
owners
,
statusCode
,
tags
));
yield
put
(
getTableDataSuccess
(
data
,
owners
,
statusCode
,
tags
));
}
catch
(
e
)
{
}
catch
(
e
)
{
yield
put
(
getTableDataFailure
());
yield
put
(
getTableDataFailure
());
...
@@ -47,7 +39,7 @@ export function* getTableDescriptionWorker(action: GetTableDescriptionRequest):
...
@@ -47,7 +39,7 @@ export function* getTableDescriptionWorker(action: GetTableDescriptionRequest):
const
state
=
yield
select
();
const
state
=
yield
select
();
let
tableData
=
state
.
tableMetadata
.
tableData
;
let
tableData
=
state
.
tableMetadata
.
tableData
;
try
{
try
{
tableData
=
yield
call
(
metadataG
etTableDescription
,
state
.
tableMetadata
.
tableData
);
tableData
=
yield
call
(
API
.
g
etTableDescription
,
state
.
tableMetadata
.
tableData
);
yield
put
(
getTableDescriptionSuccess
(
tableData
));
yield
put
(
getTableDescriptionSuccess
(
tableData
));
if
(
payload
.
onSuccess
)
{
if
(
payload
.
onSuccess
)
{
yield
call
(
payload
.
onSuccess
);
yield
call
(
payload
.
onSuccess
);
...
@@ -67,7 +59,7 @@ export function* updateTableDescriptionWorker(action: UpdateTableDescriptionRequ
...
@@ -67,7 +59,7 @@ export function* updateTableDescriptionWorker(action: UpdateTableDescriptionRequ
const
{
payload
}
=
action
;
const
{
payload
}
=
action
;
const
state
=
yield
select
();
const
state
=
yield
select
();
try
{
try
{
yield
call
(
metadataU
pdateTableDescription
,
payload
.
newValue
,
state
.
tableMetadata
.
tableData
);
yield
call
(
API
.
u
pdateTableDescription
,
payload
.
newValue
,
state
.
tableMetadata
.
tableData
);
if
(
payload
.
onSuccess
)
{
if
(
payload
.
onSuccess
)
{
yield
call
(
payload
.
onSuccess
);
yield
call
(
payload
.
onSuccess
);
}
}
...
@@ -86,7 +78,7 @@ export function* getColumnDescriptionWorker(action: GetColumnDescriptionRequest)
...
@@ -86,7 +78,7 @@ export function* getColumnDescriptionWorker(action: GetColumnDescriptionRequest)
const
state
=
yield
select
();
const
state
=
yield
select
();
let
tableData
=
state
.
tableMetadata
.
tableData
;
let
tableData
=
state
.
tableMetadata
.
tableData
;
try
{
try
{
tableData
=
yield
call
(
metadataG
etColumnDescription
,
payload
.
columnIndex
,
state
.
tableMetadata
.
tableData
);
tableData
=
yield
call
(
API
.
g
etColumnDescription
,
payload
.
columnIndex
,
state
.
tableMetadata
.
tableData
);
yield
put
(
getColumnDescriptionSuccess
(
tableData
));
yield
put
(
getColumnDescriptionSuccess
(
tableData
));
if
(
payload
.
onSuccess
)
{
if
(
payload
.
onSuccess
)
{
yield
call
(
payload
.
onSuccess
);
yield
call
(
payload
.
onSuccess
);
...
@@ -106,7 +98,7 @@ export function* updateColumnDescriptionWorker(action: UpdateColumnDescriptionRe
...
@@ -106,7 +98,7 @@ export function* updateColumnDescriptionWorker(action: UpdateColumnDescriptionRe
const
{
payload
}
=
action
;
const
{
payload
}
=
action
;
const
state
=
yield
select
();
const
state
=
yield
select
();
try
{
try
{
yield
call
(
metadataU
pdateColumnDescription
,
payload
.
newValue
,
payload
.
columnIndex
,
state
.
tableMetadata
.
tableData
);
yield
call
(
API
.
u
pdateColumnDescription
,
payload
.
newValue
,
payload
.
columnIndex
,
state
.
tableMetadata
.
tableData
);
if
(
payload
.
onSuccess
)
{
if
(
payload
.
onSuccess
)
{
yield
call
(
payload
.
onSuccess
);
yield
call
(
payload
.
onSuccess
);
}
}
...
@@ -122,7 +114,7 @@ export function* updateColumnDescriptionWatcher(): SagaIterator {
...
@@ -122,7 +114,7 @@ export function* updateColumnDescriptionWatcher(): SagaIterator {
export
function
*
getLastIndexedWorker
(
action
:
GetLastIndexedRequest
):
SagaIterator
{
export
function
*
getLastIndexedWorker
(
action
:
GetLastIndexedRequest
):
SagaIterator
{
try
{
try
{
const
lastIndexed
=
yield
call
(
metadataG
etLastIndexed
);
const
lastIndexed
=
yield
call
(
API
.
g
etLastIndexed
);
yield
put
(
getLastIndexedSuccess
(
lastIndexed
));
yield
put
(
getLastIndexedSuccess
(
lastIndexed
));
}
catch
(
e
)
{
}
catch
(
e
)
{
yield
put
(
getLastIndexedFailure
());
yield
put
(
getLastIndexedFailure
());
...
@@ -134,7 +126,7 @@ export function* getLastIndexedWatcher(): SagaIterator {
...
@@ -134,7 +126,7 @@ export function* getLastIndexedWatcher(): SagaIterator {
export
function
*
getPreviewDataWorker
(
action
:
GetPreviewDataRequest
):
SagaIterator
{
export
function
*
getPreviewDataWorker
(
action
:
GetPreviewDataRequest
):
SagaIterator
{
try
{
try
{
const
response
=
yield
call
(
metadataG
etPreviewData
,
action
.
payload
.
queryParams
);
const
response
=
yield
call
(
API
.
g
etPreviewData
,
action
.
payload
.
queryParams
);
const
{
data
,
status
}
=
response
;
const
{
data
,
status
}
=
response
;
yield
put
(
getPreviewDataSuccess
(
data
,
status
));
yield
put
(
getPreviewDataSuccess
(
data
,
status
));
}
catch
(
e
)
{
}
catch
(
e
)
{
...
...
amundsen_application/static/js/ducks/tableMetadata/tags/sagas.ts
View file @
32ab7c8b
import
{
SagaIterator
}
from
'redux-saga'
;
import
{
SagaIterator
}
from
'redux-saga'
;
import
{
all
,
call
,
put
,
select
,
takeEvery
}
from
'redux-saga/effects'
;
import
{
all
,
call
,
put
,
select
,
takeEvery
}
from
'redux-saga/effects'
;
import
{
metadataUpdateTableTags
,
metadataTableTags
}
from
'../api/v0'
;
import
*
as
API
from
'../api/v0'
;
import
{
updateTagsFailure
,
updateTagsSuccess
}
from
'./reducer'
;
import
{
updateTagsFailure
,
updateTagsSuccess
}
from
'./reducer'
;
...
@@ -11,8 +11,8 @@ export function* updateTableTagsWorker(action: UpdateTagsRequest): SagaIterator
...
@@ -11,8 +11,8 @@ export function* updateTableTagsWorker(action: UpdateTagsRequest): SagaIterator
const
state
=
yield
select
();
const
state
=
yield
select
();
const
tableData
=
state
.
tableMetadata
.
tableData
;
const
tableData
=
state
.
tableMetadata
.
tableData
;
try
{
try
{
yield
all
(
metadataU
pdateTableTags
(
action
.
payload
.
tagArray
,
tableData
.
key
));
yield
all
(
API
.
u
pdateTableTags
(
action
.
payload
.
tagArray
,
tableData
.
key
));
const
newTags
=
yield
call
(
metadata
TableTags
,
tableData
.
key
);
const
newTags
=
yield
call
(
API
.
get
TableTags
,
tableData
.
key
);
yield
put
(
updateTagsSuccess
(
newTags
));
yield
put
(
updateTagsSuccess
(
newTags
));
}
catch
(
e
)
{
}
catch
(
e
)
{
yield
put
(
updateTagsFailure
());
yield
put
(
updateTagsFailure
());
...
...
amundsen_application/static/js/ducks/tableMetadata/tags/tests/index.spec.ts
View file @
32ab7c8b
...
@@ -4,7 +4,7 @@ import { UpdateMethod, UpdateTagData, Tag } from 'interfaces';
...
@@ -4,7 +4,7 @@ import { UpdateMethod, UpdateTagData, Tag } from 'interfaces';
import
globalState
from
'fixtures/globalState'
;
import
globalState
from
'fixtures/globalState'
;
import
*
as
apis
from
'../../api/v0'
;
import
*
as
API
from
'../../api/v0'
;
import
reducer
,
{
import
reducer
,
{
updateTags
,
updateTagsFailure
,
updateTagsSuccess
,
updateTags
,
updateTagsFailure
,
updateTagsSuccess
,
...
@@ -16,7 +16,7 @@ import { updateTableTagsWorker, updateTableTagsWatcher } from '../sagas';
...
@@ -16,7 +16,7 @@ import { updateTableTagsWorker, updateTableTagsWatcher } from '../sagas';
import
{
GetTableData
,
UpdateTags
}
from
'../../types'
;
import
{
GetTableData
,
UpdateTags
}
from
'../../types'
;
const
metadataUpdateTableTagsSpy
=
jest
.
spyOn
(
apis
,
'metadataU
pdateTableTags'
).
mockImplementation
((
payload
,
key
)
=>
[]);
const
updateTableTagsSpy
=
jest
.
spyOn
(
API
,
'u
pdateTableTags'
).
mockImplementation
((
payload
,
key
)
=>
[]);
describe
(
'tableMetadata:tags ducks'
,
()
=>
{
describe
(
'tableMetadata:tags ducks'
,
()
=>
{
let
expectedTags
:
Tag
[];
let
expectedTags
:
Tag
[];
...
@@ -119,8 +119,8 @@ describe('tableMetadata:tags ducks', () => {
...
@@ -119,8 +119,8 @@ describe('tableMetadata:tags ducks', () => {
it
(
'executes flow for updating tags and returning up to date tag array'
,
()
=>
{
it
(
'executes flow for updating tags and returning up to date tag array'
,
()
=>
{
testSaga
(
updateTableTagsWorker
,
updateTags
(
updatePayload
))
testSaga
(
updateTableTagsWorker
,
updateTags
(
updatePayload
))
.
next
().
select
()
.
next
().
select
()
.
next
(
globalState
).
all
(
apis
.
metadataU
pdateTableTags
(
updatePayload
,
globalState
.
tableMetadata
.
tableData
.
key
))
.
next
(
globalState
).
all
(
API
.
u
pdateTableTags
(
updatePayload
,
globalState
.
tableMetadata
.
tableData
.
key
))
.
next
().
call
(
apis
.
metadata
TableTags
,
globalState
.
tableMetadata
.
tableData
.
key
)
.
next
().
call
(
API
.
get
TableTags
,
globalState
.
tableMetadata
.
tableData
.
key
)
.
next
(
expectedTags
).
put
(
updateTagsSuccess
(
expectedTags
))
.
next
(
expectedTags
).
put
(
updateTagsSuccess
(
expectedTags
))
.
next
().
isDone
();
.
next
().
isDone
();
});
});
...
...
amundsen_application/static/js/ducks/tableMetadata/tests/index.spec.ts
View file @
32ab7c8b
...
@@ -4,15 +4,7 @@ import { PreviewData, PreviewQueryParams, TableMetadata, Tag, UpdateMethod, Upda
...
@@ -4,15 +4,7 @@ import { PreviewData, PreviewQueryParams, TableMetadata, Tag, UpdateMethod, Upda
import
globalState
from
'fixtures/globalState'
;
import
globalState
from
'fixtures/globalState'
;
import
{
import
*
as
API
from
'../api/v0'
;
metadataGetLastIndexed
,
metadataGetPreviewData
,
metadataGetTableData
,
metadataGetColumnDescription
,
metadataGetTableDescription
,
metadataUpdateColumnDescription
,
metadataUpdateTableDescription
,
}
from
'../api/v0'
;
import
reducer
,
{
import
reducer
,
{
getTableData
,
getTableDataFailure
,
getTableDataSuccess
,
getTableData
,
getTableDataFailure
,
getTableDataSuccess
,
...
@@ -317,7 +309,8 @@ describe('reducer', () => {
...
@@ -317,7 +309,8 @@ describe('reducer', () => {
describe
(
'getTableDataWatcher'
,
()
=>
{
describe
(
'getTableDataWatcher'
,
()
=>
{
it
(
'takes every GetTableData.REQUEST with getTableDataWorker'
,
()
=>
{
it
(
'takes every GetTableData.REQUEST with getTableDataWorker'
,
()
=>
{
testSaga
(
getTableDataWatcher
)
testSaga
(
getTableDataWatcher
)
.
next
().
takeEvery
(
GetTableData
.
REQUEST
,
getTableDataWorker
);
.
next
().
takeEvery
(
GetTableData
.
REQUEST
,
getTableDataWorker
)
.
next
().
isDone
();
});
});
});
});
...
@@ -325,7 +318,7 @@ describe('reducer', () => {
...
@@ -325,7 +318,7 @@ describe('reducer', () => {
it
(
'executes flow for getting table data'
,
()
=>
{
it
(
'executes flow for getting table data'
,
()
=>
{
const
mockResult
=
{
data
:
expectedData
,
owners
:
expectedOwners
,
statusCode
:
expectedStatus
,
tags
:
expectedTags
};
const
mockResult
=
{
data
:
expectedData
,
owners
:
expectedOwners
,
statusCode
:
expectedStatus
,
tags
:
expectedTags
};
testSaga
(
getTableDataWorker
,
getTableData
(
testKey
,
testIndex
,
testSource
))
testSaga
(
getTableDataWorker
,
getTableData
(
testKey
,
testIndex
,
testSource
))
.
next
().
call
(
metadataG
etTableData
,
testKey
,
testIndex
,
testSource
)
.
next
().
call
(
API
.
g
etTableData
,
testKey
,
testIndex
,
testSource
)
.
next
(
mockResult
).
put
(
getTableDataSuccess
(
expectedData
,
expectedOwners
,
expectedStatus
,
expectedTags
))
.
next
(
mockResult
).
put
(
getTableDataSuccess
(
expectedData
,
expectedOwners
,
expectedStatus
,
expectedTags
))
.
next
().
isDone
();
.
next
().
isDone
();
});
});
...
@@ -340,7 +333,8 @@ describe('reducer', () => {
...
@@ -340,7 +333,8 @@ describe('reducer', () => {
describe
(
'getTableDescriptionWatcher'
,
()
=>
{
describe
(
'getTableDescriptionWatcher'
,
()
=>
{
it
(
'takes every GetTableDescription.REQUEST with getTableDescriptionWorker'
,
()
=>
{
it
(
'takes every GetTableDescription.REQUEST with getTableDescriptionWorker'
,
()
=>
{
testSaga
(
getTableDescriptionWatcher
)
testSaga
(
getTableDescriptionWatcher
)
.
next
().
takeEvery
(
GetTableDescription
.
REQUEST
,
getTableDescriptionWorker
);
.
next
().
takeEvery
(
GetTableDescription
.
REQUEST
,
getTableDescriptionWorker
)
.
next
().
isDone
();
});
});
});
});
...
@@ -352,7 +346,7 @@ describe('reducer', () => {
...
@@ -352,7 +346,7 @@ describe('reducer', () => {
sagaTest
=
(
action
)
=>
{
sagaTest
=
(
action
)
=>
{
return
testSaga
(
getTableDescriptionWorker
,
action
)
return
testSaga
(
getTableDescriptionWorker
,
action
)
.
next
().
select
()
.
next
().
select
()
.
next
(
globalState
).
call
(
metadataG
etTableDescription
,
globalState
.
tableMetadata
.
tableData
)
.
next
(
globalState
).
call
(
API
.
g
etTableDescription
,
globalState
.
tableMetadata
.
tableData
)
.
next
(
mockNewTableData
).
put
(
getTableDescriptionSuccess
(
mockNewTableData
))
.
next
(
mockNewTableData
).
put
(
getTableDescriptionSuccess
(
mockNewTableData
))
};
};
});
});
...
@@ -394,7 +388,8 @@ describe('reducer', () => {
...
@@ -394,7 +388,8 @@ describe('reducer', () => {
describe
(
'updateTableDescriptionWatcher'
,
()
=>
{
describe
(
'updateTableDescriptionWatcher'
,
()
=>
{
it
(
'takes every UpdateTableDescription.REQUEST with updateTableDescriptionWorker'
,
()
=>
{
it
(
'takes every UpdateTableDescription.REQUEST with updateTableDescriptionWorker'
,
()
=>
{
testSaga
(
updateTableDescriptionWatcher
)
testSaga
(
updateTableDescriptionWatcher
)
.
next
().
takeEvery
(
UpdateTableDescription
.
REQUEST
,
updateTableDescriptionWorker
);
.
next
().
takeEvery
(
UpdateTableDescription
.
REQUEST
,
updateTableDescriptionWorker
)
.
next
().
isDone
();
});
});
});
});
...
@@ -405,7 +400,7 @@ describe('reducer', () => {
...
@@ -405,7 +400,7 @@ describe('reducer', () => {
sagaTest
=
(
mockSuccess
)
=>
{
sagaTest
=
(
mockSuccess
)
=>
{
return
testSaga
(
updateTableDescriptionWorker
,
updateTableDescription
(
newDescription
,
mockSuccess
,
null
))
return
testSaga
(
updateTableDescriptionWorker
,
updateTableDescription
(
newDescription
,
mockSuccess
,
null
))
.
next
().
select
()
.
next
().
select
()
.
next
(
globalState
).
call
(
metadataU
pdateTableDescription
,
newDescription
,
globalState
.
tableMetadata
.
tableData
)
.
next
(
globalState
).
call
(
API
.
u
pdateTableDescription
,
newDescription
,
globalState
.
tableMetadata
.
tableData
)
};
};
});
});
it
(
'without success callback'
,
()
=>
{
it
(
'without success callback'
,
()
=>
{
...
@@ -445,7 +440,8 @@ describe('reducer', () => {
...
@@ -445,7 +440,8 @@ describe('reducer', () => {
describe
(
'getColumnDescriptionWatcher'
,
()
=>
{
describe
(
'getColumnDescriptionWatcher'
,
()
=>
{
it
(
'takes every GetColumnDescription.REQUEST with getColumnDescriptionWorker'
,
()
=>
{
it
(
'takes every GetColumnDescription.REQUEST with getColumnDescriptionWorker'
,
()
=>
{
testSaga
(
getColumnDescriptionWatcher
)
testSaga
(
getColumnDescriptionWatcher
)
.
next
().
takeEvery
(
GetColumnDescription
.
REQUEST
,
getColumnDescriptionWorker
);
.
next
().
takeEvery
(
GetColumnDescription
.
REQUEST
,
getColumnDescriptionWorker
)
.
next
().
isDone
();
});
});
});
});
...
@@ -457,7 +453,7 @@ describe('reducer', () => {
...
@@ -457,7 +453,7 @@ describe('reducer', () => {
sagaTest
=
(
action
)
=>
{
sagaTest
=
(
action
)
=>
{
return
testSaga
(
getColumnDescriptionWorker
,
action
)
return
testSaga
(
getColumnDescriptionWorker
,
action
)
.
next
().
select
()
.
next
().
select
()
.
next
(
globalState
).
call
(
metadataG
etColumnDescription
,
action
.
payload
.
columnIndex
,
globalState
.
tableMetadata
.
tableData
)
.
next
(
globalState
).
call
(
API
.
g
etColumnDescription
,
action
.
payload
.
columnIndex
,
globalState
.
tableMetadata
.
tableData
)
.
next
(
mockNewTableData
).
put
(
getColumnDescriptionSuccess
(
mockNewTableData
))
.
next
(
mockNewTableData
).
put
(
getColumnDescriptionSuccess
(
mockNewTableData
))
};
};
});
});
...
@@ -499,7 +495,8 @@ describe('reducer', () => {
...
@@ -499,7 +495,8 @@ describe('reducer', () => {
describe
(
'updateColumnDescriptionWatcher'
,
()
=>
{
describe
(
'updateColumnDescriptionWatcher'
,
()
=>
{
it
(
'takes every UpdateColumnDescription.REQUEST with updateColumnDescriptionWorker'
,
()
=>
{
it
(
'takes every UpdateColumnDescription.REQUEST with updateColumnDescriptionWorker'
,
()
=>
{
testSaga
(
updateColumnDescriptionWatcher
)
testSaga
(
updateColumnDescriptionWatcher
)
.
next
().
takeEvery
(
UpdateColumnDescription
.
REQUEST
,
updateColumnDescriptionWorker
);
.
next
().
takeEvery
(
UpdateColumnDescription
.
REQUEST
,
updateColumnDescriptionWorker
)
.
next
().
isDone
();
});
});
});
});
...
@@ -510,7 +507,7 @@ describe('reducer', () => {
...
@@ -510,7 +507,7 @@ describe('reducer', () => {
sagaTest
=
(
mockSuccess
)
=>
{
sagaTest
=
(
mockSuccess
)
=>
{
return
testSaga
(
updateColumnDescriptionWorker
,
updateColumnDescription
(
newDescription
,
columnIndex
,
mockSuccess
,
null
))
return
testSaga
(
updateColumnDescriptionWorker
,
updateColumnDescription
(
newDescription
,
columnIndex
,
mockSuccess
,
null
))
.
next
().
select
()
.
next
().
select
()
.
next
(
globalState
).
call
(
metadataU
pdateColumnDescription
,
newDescription
,
columnIndex
,
globalState
.
tableMetadata
.
tableData
)
.
next
(
globalState
).
call
(
API
.
u
pdateColumnDescription
,
newDescription
,
columnIndex
,
globalState
.
tableMetadata
.
tableData
)
};
};
});
});
it
(
'without success callback'
,
()
=>
{
it
(
'without success callback'
,
()
=>
{
...
@@ -550,14 +547,15 @@ describe('reducer', () => {
...
@@ -550,14 +547,15 @@ describe('reducer', () => {
describe
(
'getLastIndexedWatcher'
,
()
=>
{
describe
(
'getLastIndexedWatcher'
,
()
=>
{
it
(
'takes every GetLastIndexed.REQUEST with getLastIndexedWorker'
,
()
=>
{
it
(
'takes every GetLastIndexed.REQUEST with getLastIndexedWorker'
,
()
=>
{
testSaga
(
getLastIndexedWatcher
)
testSaga
(
getLastIndexedWatcher
)
.
next
().
takeEvery
(
GetLastIndexed
.
REQUEST
,
getLastIndexedWorker
);
.
next
().
takeEvery
(
GetLastIndexed
.
REQUEST
,
getLastIndexedWorker
)
.
next
().
isDone
();
});
});
});
});
describe
(
'getLastIndexedWorker'
,
()
=>
{
describe
(
'getLastIndexedWorker'
,
()
=>
{
it
(
'executes flow for getting last indexed value'
,
()
=>
{
it
(
'executes flow for getting last indexed value'
,
()
=>
{
testSaga
(
getLastIndexedWorker
,
getLastIndexed
())
testSaga
(
getLastIndexedWorker
,
getLastIndexed
())
.
next
().
call
(
metadataG
etLastIndexed
)
.
next
().
call
(
API
.
g
etLastIndexed
)
.
next
(
testEpoch
).
put
(
getLastIndexedSuccess
(
testEpoch
))
.
next
(
testEpoch
).
put
(
getLastIndexedSuccess
(
testEpoch
))
.
next
().
isDone
();
.
next
().
isDone
();
});
});
...
@@ -572,7 +570,8 @@ describe('reducer', () => {
...
@@ -572,7 +570,8 @@ describe('reducer', () => {
describe
(
'getPreviewDataWatcher'
,
()
=>
{
describe
(
'getPreviewDataWatcher'
,
()
=>
{
it
(
'takes every GetPreviewData.REQUEST with getPreviewDataWorker'
,
()
=>
{
it
(
'takes every GetPreviewData.REQUEST with getPreviewDataWorker'
,
()
=>
{
testSaga
(
getPreviewDataWatcher
)
testSaga
(
getPreviewDataWatcher
)
.
next
().
takeEvery
(
GetPreviewData
.
REQUEST
,
getPreviewDataWorker
);
.
next
().
takeEvery
(
GetPreviewData
.
REQUEST
,
getPreviewDataWorker
)
.
next
().
isDone
();
});
});
});
});
...
@@ -580,7 +579,7 @@ describe('reducer', () => {
...
@@ -580,7 +579,7 @@ describe('reducer', () => {
it
(
'executes flow for getting preview data'
,
()
=>
{
it
(
'executes flow for getting preview data'
,
()
=>
{
const
mockResponse
=
{
data
:
previewData
,
status
:
200
};
const
mockResponse
=
{
data
:
previewData
,
status
:
200
};
testSaga
(
getPreviewDataWorker
,
getPreviewData
(
queryParams
))
testSaga
(
getPreviewDataWorker
,
getPreviewData
(
queryParams
))
.
next
().
call
(
metadataG
etPreviewData
,
queryParams
)
.
next
().
call
(
API
.
g
etPreviewData
,
queryParams
)
.
next
(
mockResponse
).
put
(
getPreviewDataSuccess
(
previewData
,
200
))
.
next
(
mockResponse
).
put
(
getPreviewDataSuccess
(
previewData
,
200
))
.
next
().
isDone
();
.
next
().
isDone
();
});
});
...
...
amundsen_application/static/js/ducks/user/api/tests/index.spec.ts
View file @
32ab7c8b
...
@@ -4,16 +4,13 @@ import globalState from 'fixtures/globalState';
...
@@ -4,16 +4,13 @@ import globalState from 'fixtures/globalState';
import
{
LoggedInUser
,
PeopleUser
,
Resource
}
from
'interfaces'
;
import
{
LoggedInUser
,
PeopleUser
,
Resource
}
from
'interfaces'
;
import
{
import
*
as
API
from
'../v0'
;
loggedInUser
,
userById
,
userOwn
,
userRead
,
LoggedInUserAPI
,
UserAPI
,
UserOwnAPI
,
UserReadAPI
}
from
'../v0'
;
jest
.
mock
(
'axios'
);
jest
.
mock
(
'axios'
);
describe
(
'
l
oggedInUser'
,
()
=>
{
describe
(
'
getL
oggedInUser'
,
()
=>
{
let
axiosMock
;
let
axiosMock
;
let
mockGetResponse
:
AxiosResponse
<
LoggedInUserAPI
>
;
let
mockGetResponse
:
AxiosResponse
<
API
.
LoggedInUserAPI
>
;
let
testUser
:
LoggedInUser
;
let
testUser
:
LoggedInUser
;
beforeAll
(()
=>
{
beforeAll
(()
=>
{
testUser
=
globalState
.
user
.
loggedInUser
;
testUser
=
globalState
.
user
.
loggedInUser
;
...
@@ -32,14 +29,14 @@ describe('loggedInUser', () => {
...
@@ -32,14 +29,14 @@ describe('loggedInUser', () => {
it
(
'calls axios with correct parameters'
,
async
()
=>
{
it
(
'calls axios with correct parameters'
,
async
()
=>
{
expect
.
assertions
(
1
);
expect
.
assertions
(
1
);
await
l
oggedInUser
().
then
(
user
=>
{
await
API
.
getL
oggedInUser
().
then
(
user
=>
{
expect
(
axiosMock
).
toHaveBeenCalledWith
(
`/api/auth_user`
);
expect
(
axiosMock
).
toHaveBeenCalledWith
(
`/api/auth_user`
);
});
});
});
});
it
(
'returns user from response data'
,
async
()
=>
{
it
(
'returns user from response data'
,
async
()
=>
{
expect
.
assertions
(
1
);
expect
.
assertions
(
1
);
await
l
oggedInUser
().
then
(
user
=>
{
await
API
.
getL
oggedInUser
().
then
(
user
=>
{
expect
(
user
).
toBe
(
testUser
);
expect
(
user
).
toBe
(
testUser
);
});
});
});
});
...
@@ -49,9 +46,9 @@ describe('loggedInUser', () => {
...
@@ -49,9 +46,9 @@ describe('loggedInUser', () => {
})
})
});
});
describe
(
'
userById
'
,
()
=>
{
describe
(
'
getUser
'
,
()
=>
{
let
axiosMock
;
let
axiosMock
;
let
mockGetResponse
:
AxiosResponse
<
UserAPI
>
;
let
mockGetResponse
:
AxiosResponse
<
API
.
UserAPI
>
;
let
testId
:
string
;
let
testId
:
string
;
let
testUser
:
PeopleUser
;
let
testUser
:
PeopleUser
;
beforeAll
(()
=>
{
beforeAll
(()
=>
{
...
@@ -72,14 +69,14 @@ describe('userById', () => {
...
@@ -72,14 +69,14 @@ describe('userById', () => {
it
(
'calls axios with correct parameters'
,
async
()
=>
{
it
(
'calls axios with correct parameters'
,
async
()
=>
{
expect
.
assertions
(
1
);
expect
.
assertions
(
1
);
await
userById
(
testId
).
then
(
user
=>
{
await
API
.
getUser
(
testId
).
then
(
user
=>
{
expect
(
axiosMock
).
toHaveBeenCalledWith
(
`/api/metadata/v0/user?user_id=
${
testId
}
`
);
expect
(
axiosMock
).
toHaveBeenCalledWith
(
`/api/metadata/v0/user?user_id=
${
testId
}
`
);
});
});
});
});
it
(
'returns user from response data'
,
async
()
=>
{
it
(
'returns user from response data'
,
async
()
=>
{
expect
.
assertions
(
1
);
expect
.
assertions
(
1
);
await
userById
(
testId
).
then
(
user
=>
{
await
API
.
getUser
(
testId
).
then
(
user
=>
{
expect
(
user
).
toBe
(
testUser
);
expect
(
user
).
toBe
(
testUser
);
});
});
});
});
...
@@ -89,9 +86,9 @@ describe('userById', () => {
...
@@ -89,9 +86,9 @@ describe('userById', () => {
})
})
});
});
describe
(
'
u
serOwn'
,
()
=>
{
describe
(
'
getU
serOwn'
,
()
=>
{
let
axiosMock
;
let
axiosMock
;
let
mockGetResponse
:
AxiosResponse
<
UserOwnAPI
>
;
let
mockGetResponse
:
AxiosResponse
<
API
.
UserOwnAPI
>
;
let
testId
:
string
;
let
testId
:
string
;
let
testResources
:
Resource
[];
let
testResources
:
Resource
[];
beforeAll
(()
=>
{
beforeAll
(()
=>
{
...
@@ -112,14 +109,14 @@ describe('userOwn', () => {
...
@@ -112,14 +109,14 @@ describe('userOwn', () => {
it
(
'calls axios with correct parameters'
,
async
()
=>
{
it
(
'calls axios with correct parameters'
,
async
()
=>
{
expect
.
assertions
(
1
);
expect
.
assertions
(
1
);
await
u
serOwn
(
testId
).
then
(
data
=>
{
await
API
.
getU
serOwn
(
testId
).
then
(
data
=>
{
expect
(
axiosMock
).
toHaveBeenCalledWith
(
`/api/metadata/v0/user/own?user_id=
${
testId
}
`
);
expect
(
axiosMock
).
toHaveBeenCalledWith
(
`/api/metadata/v0/user/own?user_id=
${
testId
}
`
);
});
});
});
});
it
(
'returns response data with owned resources'
,
async
()
=>
{
it
(
'returns response data with owned resources'
,
async
()
=>
{
expect
.
assertions
(
1
);
expect
.
assertions
(
1
);
await
u
serOwn
(
testId
).
then
(
data
=>
{
await
API
.
getU
serOwn
(
testId
).
then
(
data
=>
{
expect
(
data
.
own
).
toBe
(
testResources
);
expect
(
data
.
own
).
toBe
(
testResources
);
});
});
});
});
...
@@ -129,9 +126,9 @@ describe('userOwn', () => {
...
@@ -129,9 +126,9 @@ describe('userOwn', () => {
})
})
});
});
describe
(
'
u
serRead'
,
()
=>
{
describe
(
'
getU
serRead'
,
()
=>
{
let
axiosMock
;
let
axiosMock
;
let
mockGetResponse
:
AxiosResponse
<
UserReadAPI
>
;
let
mockGetResponse
:
AxiosResponse
<
API
.
UserReadAPI
>
;
let
testId
:
string
;
let
testId
:
string
;
let
testResources
:
Resource
[];
let
testResources
:
Resource
[];
beforeAll
(()
=>
{
beforeAll
(()
=>
{
...
@@ -152,14 +149,14 @@ describe('userRead', () => {
...
@@ -152,14 +149,14 @@ describe('userRead', () => {
it
(
'calls axios with correct parameters'
,
async
()
=>
{
it
(
'calls axios with correct parameters'
,
async
()
=>
{
expect
.
assertions
(
1
);
expect
.
assertions
(
1
);
await
u
serRead
(
testId
).
then
(
data
=>
{
await
API
.
getU
serRead
(
testId
).
then
(
data
=>
{
expect
(
axiosMock
).
toHaveBeenCalledWith
(
`/api/metadata/v0/user/read?user_id=
${
testId
}
`
);
expect
(
axiosMock
).
toHaveBeenCalledWith
(
`/api/metadata/v0/user/read?user_id=
${
testId
}
`
);
});
});
});
});
it
(
'returns response data with frequently read resources'
,
async
()
=>
{
it
(
'returns response data with frequently read resources'
,
async
()
=>
{
expect
.
assertions
(
1
);
expect
.
assertions
(
1
);
await
u
serRead
(
testId
).
then
(
data
=>
{
await
API
.
getU
serRead
(
testId
).
then
(
data
=>
{
expect
(
data
.
read
).
toBe
(
testResources
);
expect
(
data
.
read
).
toBe
(
testResources
);
});
});
});
});
...
...
amundsen_application/static/js/ducks/user/api/v0.ts
View file @
32ab7c8b
...
@@ -7,28 +7,28 @@ export type UserAPI = { user: PeopleUser; msg: string; };
...
@@ -7,28 +7,28 @@ export type UserAPI = { user: PeopleUser; msg: string; };
export
type
UserOwnAPI
=
{
own
:
Resource
[],
msg
:
string
;
};
export
type
UserOwnAPI
=
{
own
:
Resource
[],
msg
:
string
;
};
export
type
UserReadAPI
=
{
read
:
Resource
[],
msg
:
string
;
};
export
type
UserReadAPI
=
{
read
:
Resource
[],
msg
:
string
;
};
export
function
l
oggedInUser
()
{
export
function
getL
oggedInUser
()
{
return
axios
.
get
(
`/api/auth_user`
)
return
axios
.
get
(
`/api/auth_user`
)
.
then
((
response
:
AxiosResponse
<
LoggedInUserAPI
>
)
=>
{
.
then
((
response
:
AxiosResponse
<
LoggedInUserAPI
>
)
=>
{
return
response
.
data
.
user
;
return
response
.
data
.
user
;
});
});
}
}
export
function
userById
(
userId
:
string
)
{
export
function
getUser
(
userId
:
string
)
{
return
axios
.
get
(
`/api/metadata/v0/user?user_id=
${
userId
}
`
)
return
axios
.
get
(
`/api/metadata/v0/user?user_id=
${
userId
}
`
)
.
then
((
response
:
AxiosResponse
<
UserAPI
>
)
=>
{
.
then
((
response
:
AxiosResponse
<
UserAPI
>
)
=>
{
return
response
.
data
.
user
;
return
response
.
data
.
user
;
});
});
}
}
export
function
u
serOwn
(
userId
:
string
)
{
export
function
getU
serOwn
(
userId
:
string
)
{
return
axios
.
get
(
`/api/metadata/v0/user/own?user_id=
${
userId
}
`
)
return
axios
.
get
(
`/api/metadata/v0/user/own?user_id=
${
userId
}
`
)
.
then
((
response
:
AxiosResponse
<
UserOwnAPI
>
)
=>
{
.
then
((
response
:
AxiosResponse
<
UserOwnAPI
>
)
=>
{
return
response
.
data
return
response
.
data
});
});
}
}
export
function
u
serRead
(
userId
:
string
)
{
export
function
getU
serRead
(
userId
:
string
)
{
return
axios
.
get
(
`/api/metadata/v0/user/read?user_id=
${
userId
}
`
)
return
axios
.
get
(
`/api/metadata/v0/user/read?user_id=
${
userId
}
`
)
.
then
((
response
:
AxiosResponse
<
UserReadAPI
>
)
=>
{
.
then
((
response
:
AxiosResponse
<
UserReadAPI
>
)
=>
{
return
response
.
data
return
response
.
data
...
...
amundsen_application/static/js/ducks/user/sagas.ts
View file @
32ab7c8b
import
{
SagaIterator
}
from
'redux-saga'
;
import
{
SagaIterator
}
from
'redux-saga'
;
import
{
call
,
put
,
takeEvery
}
from
'redux-saga/effects'
;
import
{
call
,
put
,
takeEvery
}
from
'redux-saga/effects'
;
import
{
loggedInUser
,
userById
,
userOwn
,
userRead
}
from
'./api/v0'
;
import
*
as
API
from
'./api/v0'
;
import
{
import
{
GetLoggedInUser
,
GetLoggedInUser
,
...
@@ -22,7 +22,7 @@ import {
...
@@ -22,7 +22,7 @@ import {
export
function
*
getLoggedInUserWorker
():
SagaIterator
{
export
function
*
getLoggedInUserWorker
():
SagaIterator
{
try
{
try
{
const
user
=
yield
call
(
l
oggedInUser
);
const
user
=
yield
call
(
API
.
getL
oggedInUser
);
yield
put
(
getLoggedInUserSuccess
(
user
));
yield
put
(
getLoggedInUserSuccess
(
user
));
}
catch
(
e
)
{
}
catch
(
e
)
{
yield
put
(
getLoggedInUserFailure
());
yield
put
(
getLoggedInUserFailure
());
...
@@ -34,7 +34,7 @@ export function* getLoggedInUserWatcher(): SagaIterator {
...
@@ -34,7 +34,7 @@ export function* getLoggedInUserWatcher(): SagaIterator {
export
function
*
getUserWorker
(
action
:
GetUserRequest
):
SagaIterator
{
export
function
*
getUserWorker
(
action
:
GetUserRequest
):
SagaIterator
{
try
{
try
{
const
user
=
yield
call
(
userById
,
action
.
payload
.
userId
);
const
user
=
yield
call
(
API
.
getUser
,
action
.
payload
.
userId
);
yield
put
(
getUserSuccess
(
user
));
yield
put
(
getUserSuccess
(
user
));
}
catch
(
e
)
{
}
catch
(
e
)
{
yield
put
(
getUserFailure
());
yield
put
(
getUserFailure
());
...
@@ -46,7 +46,7 @@ export function* getUserWatcher(): SagaIterator {
...
@@ -46,7 +46,7 @@ export function* getUserWatcher(): SagaIterator {
export
function
*
getUserOwnWorker
(
action
:
GetUserOwnRequest
):
SagaIterator
{
export
function
*
getUserOwnWorker
(
action
:
GetUserOwnRequest
):
SagaIterator
{
try
{
try
{
const
responseData
=
yield
call
(
u
serOwn
,
action
.
payload
.
userId
);
const
responseData
=
yield
call
(
API
.
getU
serOwn
,
action
.
payload
.
userId
);
yield
put
(
getUserOwnSuccess
(
responseData
.
own
));
yield
put
(
getUserOwnSuccess
(
responseData
.
own
));
}
catch
(
e
)
{
}
catch
(
e
)
{
yield
put
(
getUserOwnFailure
())
yield
put
(
getUserOwnFailure
())
...
@@ -59,7 +59,7 @@ export function* getUserOwnWatcher(): SagaIterator {
...
@@ -59,7 +59,7 @@ export function* getUserOwnWatcher(): SagaIterator {
export
function
*
getUserReadWorker
(
action
:
GetUserReadRequest
):
SagaIterator
{
export
function
*
getUserReadWorker
(
action
:
GetUserReadRequest
):
SagaIterator
{
try
{
try
{
const
responseData
=
yield
call
(
u
serRead
,
action
.
payload
.
userId
);
const
responseData
=
yield
call
(
API
.
getU
serRead
,
action
.
payload
.
userId
);
yield
put
(
getUserReadSuccess
(
responseData
.
read
));
yield
put
(
getUserReadSuccess
(
responseData
.
read
));
}
catch
(
e
)
{
}
catch
(
e
)
{
yield
put
(
getUserReadFailure
())
yield
put
(
getUserReadFailure
())
...
...
amundsen_application/static/js/ducks/user/tests/index.spec.ts
View file @
32ab7c8b
...
@@ -4,7 +4,7 @@ import { LoggedInUser, PeopleUser, Resource } from 'interfaces';
...
@@ -4,7 +4,7 @@ import { LoggedInUser, PeopleUser, Resource } from 'interfaces';
import
globalState
from
'fixtures/globalState'
;
import
globalState
from
'fixtures/globalState'
;
import
{
loggedInUser
,
userById
,
userOwn
,
userRead
}
from
'../api/v0'
;
import
*
as
API
from
'../api/v0'
;
import
reducer
,
{
import
reducer
,
{
getLoggedInUser
,
getLoggedInUserFailure
,
getLoggedInUserSuccess
,
getLoggedInUser
,
getLoggedInUserFailure
,
getLoggedInUserSuccess
,
getUser
,
getUserFailure
,
getUserSuccess
,
getUser
,
getUserFailure
,
getUserSuccess
,
...
@@ -233,7 +233,7 @@ describe('user ducks', () => {
...
@@ -233,7 +233,7 @@ describe('user ducks', () => {
describe
(
'getLoggedInUserWorker'
,
()
=>
{
describe
(
'getLoggedInUserWorker'
,
()
=>
{
it
(
'executes flow for returning the currentUser'
,
()
=>
{
it
(
'executes flow for returning the currentUser'
,
()
=>
{
testSaga
(
getLoggedInUserWorker
,
getLoggedInUser
())
testSaga
(
getLoggedInUserWorker
,
getLoggedInUser
())
.
next
().
call
(
l
oggedInUser
)
.
next
().
call
(
API
.
getL
oggedInUser
)
.
next
(
currentUser
).
put
(
getLoggedInUserSuccess
(
currentUser
))
.
next
(
currentUser
).
put
(
getLoggedInUserSuccess
(
currentUser
))
.
next
().
isDone
();
.
next
().
isDone
();
});
});
...
@@ -255,7 +255,7 @@ describe('user ducks', () => {
...
@@ -255,7 +255,7 @@ describe('user ducks', () => {
describe
(
'getUserWorker'
,
()
=>
{
describe
(
'getUserWorker'
,
()
=>
{
it
(
'executes flow for returning a user given an id'
,
()
=>
{
it
(
'executes flow for returning a user given an id'
,
()
=>
{
testSaga
(
getUserWorker
,
getUser
(
userId
))
testSaga
(
getUserWorker
,
getUser
(
userId
))
.
next
().
call
(
userById
,
userId
)
.
next
().
call
(
API
.
getUser
,
userId
)
.
next
(
otherUser
.
user
).
put
(
getUserSuccess
(
otherUser
.
user
))
.
next
(
otherUser
.
user
).
put
(
getUserSuccess
(
otherUser
.
user
))
.
next
().
isDone
();
.
next
().
isDone
();
});
});
...
@@ -277,7 +277,7 @@ describe('user ducks', () => {
...
@@ -277,7 +277,7 @@ describe('user ducks', () => {
describe
(
'getUserOwnWorker'
,
()
=>
{
describe
(
'getUserOwnWorker'
,
()
=>
{
it
(
'executes flow for returning a users owned resources given an id'
,
()
=>
{
it
(
'executes flow for returning a users owned resources given an id'
,
()
=>
{
testSaga
(
getUserOwnWorker
,
getUserOwn
(
userId
))
testSaga
(
getUserOwnWorker
,
getUserOwn
(
userId
))
.
next
().
call
(
u
serOwn
,
userId
)
.
next
().
call
(
API
.
getU
serOwn
,
userId
)
.
next
(
otherUser
).
put
(
getUserOwnSuccess
(
otherUser
.
own
))
.
next
(
otherUser
).
put
(
getUserOwnSuccess
(
otherUser
.
own
))
.
next
().
isDone
();
.
next
().
isDone
();
});
});
...
@@ -299,7 +299,7 @@ describe('user ducks', () => {
...
@@ -299,7 +299,7 @@ describe('user ducks', () => {
describe
(
'getUserReadWorker'
,
()
=>
{
describe
(
'getUserReadWorker'
,
()
=>
{
it
(
'executes flow for returning a users frequently used resources given an id'
,
()
=>
{
it
(
'executes flow for returning a users frequently used resources given an id'
,
()
=>
{
testSaga
(
getUserReadWorker
,
getUserRead
(
userId
))
testSaga
(
getUserReadWorker
,
getUserRead
(
userId
))
.
next
().
call
(
u
serRead
,
userId
)
.
next
().
call
(
API
.
getU
serRead
,
userId
)
.
next
(
otherUser
).
put
(
getUserReadSuccess
(
otherUser
.
read
))
.
next
(
otherUser
).
put
(
getUserReadSuccess
(
otherUser
.
read
))
.
next
().
isDone
();
.
next
().
isDone
();
});
});
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment