Skip to content

Commit 2b242b7

Browse files
committed
Merge pull request #74 from openstax/test/_loaded
adding tests for when _loaded is not defined or returns falsy
2 parents 961dff6 + b306915 commit 2b242b7

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

test/crud-store.spec.coffee

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@ TestCrudConfig = CrudConfig()
88

99
ExtendedConfig =
1010
_loaded: (obj, id) ->
11-
nested : obj
11+
nested : obj unless obj.doNotModify
12+
1213
exports:
13-
testExtendedStore : ()->
14+
testExtendedStore : () ->
1415

1516
extendConfig(ExtendedConfig, new CrudConfig())
1617
{actions: ExtendedActions, store: ExtendedStore} = makeSimpleStore(ExtendedConfig)
@@ -131,8 +132,25 @@ describe 'CRUD Store', ->
131132
expect(ExtendedStore.testExtendedStore).to.be.a('function')
132133

133134

134-
it 'should change what is loaded if _loaded function is defined', ->
135+
it 'should not change what is loaded if _loaded function is undefined', ->
136+
id = 0
137+
storeObj = {hello: 'bar'}
138+
CrudActions.loaded(storeObj, id)
139+
expect(CrudActions._loaded).to.be.undefined
140+
expect(CrudStore.get(id)).to.deep.equal(storeObj)
141+
142+
143+
it 'should change what is loaded if _loaded function is defined and returns', ->
135144
id = 0
136145
nestedStore = {hello: 'bar'}
137146
ExtendedActions.loaded(nestedStore, id)
147+
expect(ExtendedConfig._loaded(nestedStore, id)).to.not.be.undefined
138148
expect(ExtendedStore.get(id).nested).to.deep.equal(nestedStore)
149+
150+
151+
it 'should not change what is loaded if _loaded function returns falsy', ->
152+
id = 0
153+
storeObj = {hello: 'bar', doNotModify: true}
154+
ExtendedActions.loaded(storeObj, id)
155+
expect(ExtendedConfig._loaded(storeObj, id)).to.be.undefined
156+
expect(ExtendedStore.get(id)).to.deep.equal(storeObj)

0 commit comments

Comments
 (0)