@@ -230,6 +230,14 @@ module.exports = (common) => {
230
230
cb ( )
231
231
} )
232
232
} ,
233
+ ( cb ) => {
234
+ // get object from ipfs multihash string
235
+ ipfs . object . get ( node1 . toJSON ( ) . multihash , ( err , node ) => {
236
+ expect ( err ) . to . not . exist ( )
237
+ expect ( node ) . to . exist ( )
238
+ cb ( )
239
+ } )
240
+ } ,
233
241
( cb ) => {
234
242
expect ( node1 . data ) . to . eql ( node2 . data )
235
243
expect ( node1 . links ) . to . eql ( node2 . links )
@@ -756,39 +764,37 @@ module.exports = (common) => {
756
764
} )
757
765
758
766
describe ( 'promise API' , ( ) => {
759
- it ( 'object.new' , ( done ) => {
760
- ipfs . object . new ( )
767
+ it ( 'object.new' , ( ) => {
768
+ return ipfs . object . new ( )
761
769
. then ( ( node ) => {
762
770
const nodeJSON = node . toJSON ( )
763
771
expect ( nodeJSON . multihash ) . to . equal ( 'QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n' )
764
- done ( )
765
772
} )
766
773
} )
767
774
768
- it ( 'object.put' , ( done ) => {
775
+ it ( 'object.put' , ( ) => {
769
776
const obj = {
770
777
Data : new Buffer ( 'Some data' ) ,
771
778
Links : [ ]
772
779
}
773
780
774
- ipfs . object . put ( obj )
781
+ return ipfs . object . put ( obj )
775
782
. then ( ( node ) => {
776
783
const nodeJSON = node . toJSON ( )
777
784
expect ( obj . Data ) . to . deep . equal ( nodeJSON . data )
778
785
expect ( obj . Links ) . to . deep . equal ( nodeJSON . links )
779
786
expect ( nodeJSON . multihash ) . to . equal ( 'QmPb5f92FxKPYdT3QNBd1GKiL4tZUXUrzF4Hkpdr3Gf1gK' )
780
- done ( )
781
787
} )
782
788
} )
783
789
784
- it ( 'object.get' , ( done ) => {
790
+ it ( 'object.get' , ( ) => {
785
791
const testObj = {
786
792
Data : new Buffer ( 'get test object' ) ,
787
793
Links : [ ]
788
794
}
789
795
790
- ipfs . object . put ( testObj ) . then ( ( node1 ) => {
791
- ipfs . object . get ( node1 . multihash ) . then ( ( node2 ) => {
796
+ return ipfs . object . put ( testObj ) . then ( ( node1 ) => {
797
+ return ipfs . object . get ( node1 . multihash ) . then ( ( node2 ) => {
792
798
// because js-ipfs-api can't infer if the
793
799
// returned Data is Buffer or String
794
800
if ( typeof node2 . data === 'string' ) {
@@ -797,40 +803,44 @@ module.exports = (common) => {
797
803
798
804
expect ( node1 . data ) . to . deep . equal ( node2 . data )
799
805
expect ( node1 . links ) . to . deep . equal ( node2 . links )
800
- done ( )
801
806
} )
802
807
} )
803
808
} )
804
809
805
- it ( 'object.data' , ( done ) => {
810
+ it ( 'object.get multihash string' , ( ) => {
811
+ return ipfs . object . get ( 'QmPb5f92FxKPYdT3QNBd1GKiL4tZUXUrzF4Hkpdr3Gf1gK' ) . then ( ( node ) => {
812
+ expect ( node . data ) . to . exist ( )
813
+ } )
814
+ } )
815
+
816
+ it ( 'object.data' , ( ) => {
806
817
const testObj = {
807
818
Data : new Buffer ( 'get test object' ) ,
808
819
Links : [ ]
809
820
}
810
821
811
- ipfs . object . put ( testObj ) . then ( ( node ) => {
812
- ipfs . object . data ( node . multihash ) . then ( ( data ) => {
822
+ return ipfs . object . put ( testObj ) . then ( ( node ) => {
823
+ return ipfs . object . data ( node . multihash ) . then ( ( data ) => {
813
824
// because js-ipfs-api can't infer
814
825
// if the returned Data is Buffer or String
815
826
if ( typeof data === 'string' ) {
816
827
data = new Buffer ( data )
817
828
}
818
829
expect ( node . data ) . to . deep . equal ( data )
819
- done ( )
820
830
} )
821
831
} )
822
832
} )
823
833
824
- it ( 'object.stat' , ( done ) => {
834
+ it ( 'object.stat' , ( ) => {
825
835
const testObj = {
826
836
Data : new Buffer ( 'get test object' ) ,
827
837
Links : [ ]
828
838
}
829
839
830
- ipfs . object . put ( testObj , ( err , node ) => {
840
+ return ipfs . object . put ( testObj , ( err , node ) => {
831
841
expect ( err ) . to . not . exist ( )
832
842
833
- ipfs . object . stat ( 'QmNggDXca24S6cMPEYHZjeuc4QRmofkRrAEqVL3Ms2sdJZ' , { enc : 'base58' } )
843
+ return ipfs . object . stat ( 'QmNggDXca24S6cMPEYHZjeuc4QRmofkRrAEqVL3Ms2sdJZ' , { enc : 'base58' } )
834
844
. then ( ( stats ) => {
835
845
const expected = {
836
846
Hash : 'QmNggDXca24S6cMPEYHZjeuc4QRmofkRrAEqVL3Ms2sdJZ' ,
@@ -841,24 +851,19 @@ module.exports = (common) => {
841
851
CumulativeSize : 17
842
852
}
843
853
expect ( expected ) . to . deep . equal ( stats )
844
- done ( )
845
854
} )
846
- . catch ( ( err ) => {
847
- expect ( err ) . to . not . exist ( )
848
- } )
849
855
} )
850
856
} )
851
857
852
- it ( 'object.links' , ( done ) => {
858
+ it ( 'object.links' , ( ) => {
853
859
const testObj = {
854
860
Data : new Buffer ( 'get test object' ) ,
855
861
Links : [ ]
856
862
}
857
863
858
- ipfs . object . put ( testObj ) . then ( ( node ) => {
859
- ipfs . object . links ( node . multihash ) . then ( ( links ) => {
864
+ return ipfs . object . put ( testObj ) . then ( ( node ) => {
865
+ return ipfs . object . links ( node . multihash ) . then ( ( links ) => {
860
866
expect ( node . links ) . to . eql ( links )
861
- done ( )
862
867
} )
863
868
} )
864
869
} )
@@ -873,94 +878,77 @@ module.exports = (common) => {
873
878
Links : [ ]
874
879
}
875
880
876
- before ( ( done ) => {
877
- ipfs . object . put ( obj , ( err , node ) => {
881
+ before ( ( ) => {
882
+ return ipfs . object . put ( obj , ( err , node ) => {
878
883
expect ( err ) . to . not . exist ( )
879
884
testNodeMultihash = node . multihash
880
- done ( )
881
885
} )
882
886
} )
883
887
884
- it ( '.addLink' , ( done ) => {
888
+ it ( '.addLink' , ( ) => {
885
889
let node1a
886
890
let node1b
887
891
let node2
888
-
889
- series ( [
890
- ( cb ) => {
891
- DAGNode . create ( obj . Data , obj . Links , ( err , node ) => {
892
- expect ( err ) . to . not . exist ( )
893
- node1a = node
894
- cb ( )
895
- } )
896
- } ,
897
- ( cb ) => {
898
- DAGNode . create ( new Buffer ( 'some other node' ) , ( err , node ) => {
899
- expect ( err ) . to . not . exist ( )
900
- node2 = node
901
- cb ( )
892
+ return new Promise ( ( resolve , reject ) => {
893
+ DAGNode . create ( obj . Data , obj . Links , function ( err , node ) {
894
+ if ( err ) {
895
+ return reject ( err )
896
+ }
897
+ return resolve ( node )
898
+ } )
899
+ } ) . then ( ( node ) => {
900
+ node1a = node
901
+ return new Promise ( ( resolve , reject ) => {
902
+ DAGNode . create ( new Buffer ( 'some other node' ) , function ( err , node ) {
903
+ if ( err ) {
904
+ return reject ( err )
905
+ }
906
+ return resolve ( node )
902
907
} )
903
- } ,
904
- ( cb ) => {
905
- // note: we need to put the linked obj, otherwise IPFS won't
906
- // timeout. Reason: it needs the node to get its size
907
- ipfs . object . put ( node2 , cb )
908
- } ,
909
- ( cb ) => {
910
- const link = node2 . toJSON ( )
911
- link . name = ' link-to- node'
912
- DAGNode . addLink ( node1a , link , ( err , node ) => {
913
- expect ( err ) . to . not . exist ( )
914
- node1b = node
915
- cb ( )
908
+ } ) . then ( ( node1 ) => {
909
+ node2 = node1
910
+ return ipfs . object . put ( node2 )
911
+ } )
912
+ } ) . then ( ( ) => {
913
+ const link = node2 . toJSON ( )
914
+ link . name = 'link-to-node'
915
+ return new Promise ( ( resolve , reject ) => {
916
+ DAGNode . addLink ( node1a , link , function ( err , node ) {
917
+ if ( err ) {
918
+ return reject ( err )
919
+ }
920
+ return resolve ( node )
916
921
} )
917
- } ,
918
- ( cb ) => {
919
- ipfs . object . patch . addLink ( testNodeMultihash , node1b . links [ 0 ] )
920
- . then ( ( node ) => {
921
- expect ( node1b . multihash ) . to . eql ( node . multihash )
922
- testNodeWithLinkMultihash = node . multihash
923
- testLink = node1b . links [ 0 ]
924
- cb ( )
925
- } )
926
- . catch ( ( err ) => {
927
- expect ( err ) . to . not . exist ( )
928
- } )
929
- }
930
- ] , done )
922
+ } ) . then ( ( node ) => {
923
+ node1b = node
924
+ return ipfs . object . patch . addLink ( testNodeMultihash , node1b . links [ 0 ] )
925
+ } )
926
+ } ) . then ( ( node ) => {
927
+ expect ( node1b . multihash ) . to . eql ( node . multihash )
928
+ testNodeWithLinkMultihash = node . multihash
929
+ testLink = node1b . links [ 0 ]
930
+ } )
931
931
} )
932
932
933
- it ( '.rmLink' , ( done ) => {
934
- ipfs . object . patch . rmLink ( testNodeWithLinkMultihash , testLink )
933
+ it ( '.rmLink' , ( ) => {
934
+ return ipfs . object . patch . rmLink ( testNodeWithLinkMultihash , testLink )
935
935
. then ( ( node ) => {
936
936
expect ( node . multihash ) . to . not . deep . equal ( testNodeWithLinkMultihash )
937
- done ( )
938
- } )
939
- . catch ( ( err ) => {
940
- expect ( err ) . to . not . exist ( )
941
937
} )
942
938
} )
943
939
944
- it ( '.appendData' , ( done ) => {
945
- ipfs . object . patch . appendData ( testNodeMultihash , new Buffer ( 'append' ) )
940
+ it ( '.appendData' , ( ) => {
941
+ return ipfs . object . patch . appendData ( testNodeMultihash , new Buffer ( 'append' ) )
946
942
. then ( ( node ) => {
947
943
expect ( node . multihash ) . to . not . deep . equal ( testNodeMultihash )
948
- done ( )
949
- } )
950
- . catch ( ( err ) => {
951
- expect ( err ) . to . not . exist ( )
952
944
} )
953
945
} )
954
946
955
- it ( '.setData' , ( done ) => {
956
- ipfs . object . patch . appendData ( testNodeMultihash , new Buffer ( 'set' ) )
947
+ it ( '.setData' , ( ) => {
948
+ return ipfs . object . patch . appendData ( testNodeMultihash , new Buffer ( 'set' ) )
957
949
. then ( ( node ) => {
958
950
expect ( node . multihash ) . to . not . deep . equal ( testNodeMultihash )
959
- done ( )
960
951
} )
961
- . catch ( ( err ) => {
962
- expect ( err ) . to . not . exist ( )
963
- } )
964
952
} )
965
953
} )
966
954
} )
0 commit comments