@@ -3,36 +3,42 @@ import configureMockStore from "redux-mock-store"
33import thunk from "redux-thunk"
44import * as sinopiaApi from "sinopiaApi"
55import { createState } from "stateUtils"
6- import { transfer } from "actionCreators/transfer"
6+ import { transfer , loadLocalIds } from "actionCreators/transfer"
7+ import Config from "Config"
78
89const mockStore = configureMockStore ( [ thunk ] )
910
1011const resourceUri =
1112 "https://api.development.sinopia.io/resource/7b4c275d-b0c7-40a4-80b3-e95a0d9d987c"
1213
14+ // This forces Sinopia server to use fixtures
15+ jest . spyOn ( Config , "useResourceTemplateFixtures" , "get" ) . mockReturnValue ( true )
16+
1317describe ( "transfer" , ( ) => {
1418 describe ( "successful" , ( ) => {
1519 it ( "dispatches actions to add user" , async ( ) => {
1620 sinopiaApi . postTransfer = jest . fn ( ) . mockResolvedValue ( )
1721 const store = mockStore ( createState ( ) )
1822 await store . dispatch (
19- transfer ( resourceUri , "stanford" , "ils " , "testerrorkey" )
23+ transfer ( resourceUri , "stanford" , "FOLIO" , "abc123 ", "testerrorkey" )
2024 )
2125
2226 expect ( store . getActions ( ) ) . toHaveLength ( 0 )
2327 expect ( sinopiaApi . postTransfer ) . toHaveBeenCalledWith (
2428 resourceUri ,
2529 "stanford" ,
26- "ils"
30+ "FOLIO" ,
31+ "abc123"
2732 )
2833 } )
2934 } )
30- describe ( "failure" , ( ) => {
35+
36+ describe ( "transfer failure" , ( ) => {
3137 it ( "dispatches actions to remove user" , async ( ) => {
3238 sinopiaApi . postTransfer = jest . fn ( ) . mockRejectedValue ( "Ooops!" )
3339 const store = mockStore ( createState ( ) )
3440 await store . dispatch (
35- transfer ( resourceUri , "stanford" , "ils " , "testerrorkey" )
41+ transfer ( resourceUri , "stanford" , "" , "abc123 ", "testerrorkey" )
3642 )
3743
3844 expect ( store . getActions ( ) ) . toHaveAction ( "ADD_ERROR" , {
@@ -41,4 +47,29 @@ describe("transfer", () => {
4147 } )
4248 } )
4349 } )
50+
51+ describe ( "loadLocalIds()" , ( ) => {
52+ it ( "dispatches actions to set local id" , async ( ) => {
53+ const store = mockStore ( createState ( ) )
54+ await store . dispatch (
55+ loadLocalIds (
56+ "abc123" ,
57+ [
58+ "http://localhost:3000/resource/ae93cff4-d272-43b2-a4ee-fb8651907e51" ,
59+ ] ,
60+ "testerrorkey"
61+ )
62+ )
63+
64+ const actions = store . getActions ( )
65+
66+ expect ( actions ) . toHaveAction ( "CLEAR_LOCAL_IDS" , "abc123" )
67+ expect ( actions ) . toHaveAction ( "SET_LOCAL_ID" , {
68+ resourceKey : "abc123" ,
69+ target : "SIRSI" ,
70+ group : "stanford" ,
71+ localId : "13714202" ,
72+ } )
73+ } )
74+ } )
4475} )
0 commit comments