@@ -710,41 +710,90 @@ describe('Competition Proposal', () => {
710710 arc . setAccount ( address0 )
711711 } )
712712
713- // TODO!! unskip this test. It passes locally but fails often (but not always) on travis :-(
714- it . skip ( 'pre-fetching competition.suggestions works' , async ( ) => {
713+ it ( 'pre-fetching competition.suggestions works' , async ( ) => {
715714 // find a proposal in a scheme that has > 1 votes
716715 const competition = await createCompetition ( )
717716 // check if the competition has indeed some suggestions
718717
719718 const suggestions = await competition . suggestions ( ) . pipe ( first ( ) ) . toPromise ( )
720719 expect ( suggestions . length ) . toBeGreaterThan ( 0 )
721720
722- // now we have our objects, reset the cache
721+ // now we have our objects, reset the cache
723722 await ( arc . apolloClient as any ) . cache . reset ( )
724723 expect ( ( arc . apolloClient as any ) . cache . data . data ) . toEqual ( { } )
725724
726- // // construct our superquery that will fill the cache
725+ // // construct our superquery that will fill the cache
727726 const query = gql `query {
728- proposals (where: { id: "${ competition . id } "}) {
729- competition {
727+ proposals (where: { id: "${ competition . id } "}) {
728+ ...ProposalFields
730729 id
731- suggestions { ...CompetitionSuggestionFields }
730+ competition {
731+ id
732+ suggestions {
733+ ...CompetitionSuggestionFields
734+ }
735+ }
732736 }
733- ...ProposalFields
734737 }
735- }
736- ${ Proposal . fragments . ProposalFields }
737- ${ Scheme . fragments . SchemeFields }
738- ${ CompetitionSuggestion . fragments . CompetitionSuggestionFields }
739- `
738+ ${ Proposal . fragments . ProposalFields }
739+ ${ Scheme . fragments . SchemeFields }
740+ ${ CompetitionSuggestion . fragments . CompetitionSuggestionFields }
741+ `
740742
741743 await arc . sendQuery ( query )
742744
743- // now see if we can get our informatino directly from the cache
744- const cachedSugestions = await competition . suggestions ( { } , { fetchPolicy : 'cache-only' } )
745- . pipe ( first ( ) ) . toPromise ( )
746- expect ( cachedSugestions . map ( ( v : CompetitionSuggestion ) => v . id ) )
747- . toEqual ( suggestions . map ( ( v : CompetitionSuggestion ) => v . id ) )
745+ // now see if we can get our informatino directly from the cache
746+ const cachedSuggestions = await competition . suggestions ( { } , { fetchPolicy : 'cache-only' } )
747+ . pipe ( first ( ) ) . toPromise ( )
748+ expect ( cachedSuggestions . map ( ( v : CompetitionSuggestion ) => v . id ) )
749+ . toEqual ( suggestions . map ( ( v : CompetitionSuggestion ) => v . id ) )
750+
751+ const cachedSuggestionState = await cachedSuggestions [ 0 ]
752+ . state ( { fetchPolicy : 'cache-only' } ) . pipe ( first ( ) ) . toPromise ( )
753+ expect ( cachedSuggestionState . id ) . toEqual ( cachedSuggestions [ 0 ] . id )
754+
755+ } )
756+
757+ it ( 'pre-fetching competition.suggestions works also without resetting the cache' , async ( ) => {
758+ // find a proposal in a scheme that has > 1 votes
759+ const competition = await createCompetition ( )
760+ // check if the competition has indeed some suggestions
761+
762+ const suggestions = await competition . suggestions ( ) . pipe ( first ( ) ) . toPromise ( )
763+ expect ( suggestions . length ) . toBeGreaterThan ( 0 )
764+
765+ // add some exiting data to the cache to seeif we can mess things up
766+ await arc . proposal ( competition . id ) . state ( ) . pipe ( first ( ) ) . toPromise ( )
767+
768+ // construct our superquery that will fill the cache
769+ const query = gql `query {
770+ proposals (where: { id: "${ competition . id } "}) {
771+ # id
772+ ...ProposalFields
773+ competition {
774+ id
775+ suggestions {
776+ ...CompetitionSuggestionFields
777+ }
778+ }
779+ }
780+ }
781+ ${ Proposal . fragments . ProposalFields }
782+ ${ Scheme . fragments . SchemeFields }
783+ ${ CompetitionSuggestion . fragments . CompetitionSuggestionFields }
784+ `
785+
786+ await arc . sendQuery ( query )
787+
788+ // now see if we can get our informatino directly from the cache
789+ const cachedSuggestions = await competition . suggestions ( { } , { fetchPolicy : 'cache-only' } )
790+ . pipe ( first ( ) ) . toPromise ( )
791+ expect ( cachedSuggestions . map ( ( v : CompetitionSuggestion ) => v . id ) )
792+ . toEqual ( suggestions . map ( ( v : CompetitionSuggestion ) => v . id ) )
793+
794+ const cachedSuggestionState = await cachedSuggestions [ 0 ]
795+ . state ( { fetchPolicy : 'cache-only' } ) . pipe ( first ( ) ) . toPromise ( )
796+ expect ( cachedSuggestionState . id ) . toEqual ( cachedSuggestions [ 0 ] . id )
748797
749798 } )
750799
@@ -771,7 +820,7 @@ describe('Competition Proposal', () => {
771820 // // construct our superquery that will fill the cache
772821 const query = gql `query
773822 {
774- competitionSuggestion(id: ' ${ suggestion1 . id } ' ) {
823+ competitionSuggestion(id: " ${ suggestion1 . id } " ) {
775824 id
776825 votes {
777826 ...CompetitionVoteFields
@@ -784,19 +833,15 @@ describe('Competition Proposal', () => {
784833 ${ CompetitionVote . fragments . CompetitionVoteFields }
785834 `
786835
787- let subscribed = false
788- const results : any [ ] = [ ]
789- arc . getObservable ( query , { subscribe : true , fetchPolicy : 'no-cache' } ) . subscribe ( ( x : any ) => {
790- subscribed = true
791- results . push ( x )
792- } )
793- await waitUntilTrue ( ( ) => subscribed )
836+ await arc . sendQuery ( query )
794837
795- // now see if we can get our information directly from the cache
796838 const cachedVotes = await suggestion1 . votes ( { } , { fetchPolicy : 'cache-only' } )
797839 . pipe ( first ( ) ) . toPromise ( )
798840 expect ( cachedVotes . map ( ( v : CompetitionVote ) => v . id ) )
799841 . toEqual ( votes . map ( ( v : CompetitionVote ) => v . id ) )
800842
843+ const cachedVoteState = await cachedVotes [ 0 ] . state ( { fetchPolicy : 'cache-only' } )
844+ . pipe ( first ( ) ) . toPromise ( )
845+ expect ( cachedVoteState . id ) . toEqual ( cachedVotes [ 0 ] . id )
801846 } )
802847} )
0 commit comments