@@ -541,6 +541,149 @@ func TestZECSalesCannotReleaseEscrow(t *testing.T) {
541
541
}, dbSetup , nil )
542
542
}
543
543
544
+ func TestSalesGet (t * testing.T ) {
545
+ sale := factory .NewSaleRecord ()
546
+ sale .Contract .VendorListings [0 ].Metadata .AcceptedCurrencies = []string {"BTC" }
547
+ sale .Contract .VendorListings [0 ].Metadata .CoinType = "ZEC"
548
+ sale .Contract .VendorListings [0 ].Metadata .ContractType = pb .Listing_Metadata_CRYPTOCURRENCY
549
+ dbSetup := func (testRepo * test.Repository ) error {
550
+ return testRepo .DB .Sales ().Put (sale .OrderID , * sale .Contract , sale .OrderState , false )
551
+ }
552
+
553
+ runAPITestsWithSetup (t , apiTests {
554
+ {"GET" , "/ob/sales" , "" , 200 , anyResponseJSON },
555
+ }, dbSetup , nil )
556
+
557
+ respBytes , err := httpGet ("/ob/sales" )
558
+ if err != nil {
559
+ t .Fatal (err )
560
+ }
561
+ respObj := struct {
562
+ Sales []repo.Sale `json:"sales"`
563
+ }{}
564
+ err = json .Unmarshal (respBytes , & respObj )
565
+ if err != nil {
566
+ t .Fatal (err )
567
+ }
568
+
569
+ actualSale := respObj .Sales [0 ]
570
+
571
+ if actualSale .BuyerHandle != sale .Contract .BuyerOrder .BuyerID .Handle {
572
+ t .Fatal ("Incorrect buyerHandle:" , actualSale .BuyerHandle , "\n wanted:" , sale .Contract .BuyerOrder .BuyerID .Handle )
573
+ }
574
+ if actualSale .BuyerId != sale .Contract .BuyerOrder .BuyerID .PeerID {
575
+ t .Fatal ("Incorrect buyerId:" , actualSale .BuyerId , "\n wanted:" , sale .Contract .BuyerOrder .BuyerID .PeerID )
576
+ }
577
+ if actualSale .CoinType != sale .Contract .VendorListings [0 ].Metadata .CoinType {
578
+ t .Fatal ("Incorrect coinType:" , actualSale .CoinType , "\n wanted:" , sale .Contract .VendorListings [0 ].Metadata .CoinType )
579
+ }
580
+ if actualSale .OrderId != sale .OrderID {
581
+ t .Fatal ("Incorrect orderId:" , actualSale .OrderId , "\n wanted:" , sale .OrderID )
582
+ }
583
+ if actualSale .PaymentCoin != sale .Contract .VendorListings [0 ].Metadata .AcceptedCurrencies [0 ] {
584
+ t .Fatal ("Incorrect paymentCoin:" , actualSale .PaymentCoin , "\n wanted:" , sale .Contract .VendorListings [0 ].Metadata .AcceptedCurrencies [0 ])
585
+ }
586
+ if actualSale .ShippingAddress != sale .Contract .BuyerOrder .Shipping .Address {
587
+ t .Fatal ("Incorrect shippingAddress:" , actualSale .ShippingAddress , "\n wanted:" , sale .Contract .BuyerOrder .Shipping .Address )
588
+ }
589
+ if actualSale .ShippingName != sale .Contract .BuyerOrder .Shipping .ShipTo {
590
+ t .Fatal ("Incorrect shippingName:" , actualSale .ShippingName , "\n wanted:" , sale .Contract .BuyerOrder .Shipping .ShipTo )
591
+ }
592
+ if actualSale .State != sale .OrderState .String () {
593
+ t .Fatal ("Incorrect state:" , actualSale .State , "\n wanted:" , sale .OrderState .String ())
594
+ }
595
+ }
596
+ func TestPurchasesGet (t * testing.T ) {
597
+ purchase := factory .NewPurchaseRecord ()
598
+ purchase .Contract .VendorListings [0 ].Metadata .AcceptedCurrencies = []string {"BTC" }
599
+ purchase .Contract .VendorListings [0 ].Metadata .CoinType = "ZEC"
600
+ purchase .Contract .VendorListings [0 ].Metadata .ContractType = pb .Listing_Metadata_CRYPTOCURRENCY
601
+ dbSetup := func (testRepo * test.Repository ) error {
602
+ return testRepo .DB .Purchases ().Put (purchase .OrderID , * purchase .Contract , purchase .OrderState , false )
603
+ }
604
+
605
+ runAPITestsWithSetup (t , apiTests {
606
+ {"GET" , "/ob/purchases" , "" , 200 , anyResponseJSON },
607
+ }, dbSetup , nil )
608
+
609
+ respBytes , err := httpGet ("/ob/purchases" )
610
+ if err != nil {
611
+ t .Fatal (err )
612
+ }
613
+ respObj := struct {
614
+ Purchases []repo.Purchase `json:"purchases"`
615
+ }{}
616
+ err = json .Unmarshal (respBytes , & respObj )
617
+ if err != nil {
618
+ t .Fatal (err )
619
+ }
620
+
621
+ actualPurchase := respObj .Purchases [0 ]
622
+
623
+ if actualPurchase .VendorHandle != purchase .Contract .VendorListings [0 ].VendorID .Handle {
624
+ t .Fatal ("Incorrect vendorHandle:" , actualPurchase .VendorId , "\n wanted:" , purchase .Contract .VendorListings [0 ].VendorID .Handle )
625
+ }
626
+ if actualPurchase .VendorId != purchase .Contract .VendorListings [0 ].VendorID .PeerID {
627
+ t .Fatal ("Incorrect vendorId:" , actualPurchase .VendorId , "\n wanted:" , purchase .Contract .VendorListings [0 ].VendorID .PeerID )
628
+ }
629
+ if actualPurchase .CoinType != purchase .Contract .VendorListings [0 ].Metadata .CoinType {
630
+ t .Fatal ("Incorrect coinType:" , actualPurchase .CoinType , "\n wanted:" , purchase .Contract .VendorListings [0 ].Metadata .CoinType )
631
+ }
632
+ if actualPurchase .OrderId != purchase .OrderID {
633
+ t .Fatal ("Incorrect orderId:" , actualPurchase .OrderId , "\n wanted:" , purchase .OrderID )
634
+ }
635
+ if actualPurchase .PaymentCoin != purchase .Contract .VendorListings [0 ].Metadata .AcceptedCurrencies [0 ] {
636
+ t .Fatal ("Incorrect paymentCoin:" , actualPurchase .PaymentCoin , "\n wanted:" , purchase .Contract .VendorListings [0 ].Metadata .AcceptedCurrencies [0 ])
637
+ }
638
+ if actualPurchase .ShippingAddress != purchase .Contract .BuyerOrder .Shipping .Address {
639
+ t .Fatal ("Incorrect shippingAddress:" , actualPurchase .ShippingAddress , "\n wanted:" , purchase .Contract .BuyerOrder .Shipping .Address )
640
+ }
641
+ if actualPurchase .ShippingName != purchase .Contract .BuyerOrder .Shipping .ShipTo {
642
+ t .Fatal ("Incorrect shippingName:" , actualPurchase .ShippingName , "\n wanted:" , purchase .Contract .BuyerOrder .Shipping .ShipTo )
643
+ }
644
+ if actualPurchase .State != purchase .OrderState .String () {
645
+ t .Fatal ("Incorrect state:" , actualPurchase .State , "\n wanted:" , purchase .OrderState .String ())
646
+ }
647
+ }
648
+
649
+ func TestCasesGet (t * testing.T ) {
650
+ disputeCaseRecord := factory .NewDisputeCaseRecord ()
651
+ disputeCaseRecord .BuyerContract .VendorListings [0 ].Metadata .AcceptedCurrencies = []string {"BTC" }
652
+ disputeCaseRecord .BuyerContract .VendorListings [0 ].Metadata .CoinType = "ZEC"
653
+ disputeCaseRecord .BuyerContract .VendorListings [0 ].Metadata .ContractType = pb .Listing_Metadata_CRYPTOCURRENCY
654
+ dbSetup := func (testRepo * test.Repository ) error {
655
+ return testRepo .DB .Cases ().PutRecord (disputeCaseRecord )
656
+ }
657
+
658
+ runAPITestsWithSetup (t , apiTests {
659
+ {"GET" , "/ob/cases" , "" , 200 , anyResponseJSON },
660
+ }, dbSetup , nil )
661
+
662
+ respBytes , err := httpGet ("/ob/cases" )
663
+ if err != nil {
664
+ t .Fatal (err )
665
+ }
666
+ respObj := struct {
667
+ Cases []repo.Case `json:"cases"`
668
+ }{}
669
+ err = json .Unmarshal (respBytes , & respObj )
670
+ if err != nil {
671
+ t .Fatal (err )
672
+ }
673
+
674
+ actualCase := respObj .Cases [0 ]
675
+
676
+ if actualCase .CoinType != disputeCaseRecord .BuyerContract .VendorListings [0 ].Metadata .CoinType {
677
+ t .Fatal ("Incorrect coinType:" , actualCase .CoinType , "\n wanted:" , disputeCaseRecord .BuyerContract .VendorListings [0 ].Metadata .CoinType )
678
+ }
679
+ if actualCase .PaymentCoin != disputeCaseRecord .BuyerContract .VendorListings [0 ].Metadata .AcceptedCurrencies [0 ] {
680
+ t .Fatal ("Incorrect paymentCoin:" , actualCase .PaymentCoin , "\n wanted:" , disputeCaseRecord .BuyerContract .VendorListings [0 ].Metadata .AcceptedCurrencies [0 ])
681
+ }
682
+ if actualCase .State != disputeCaseRecord .OrderState .String () {
683
+ t .Fatal ("Incorrect state:" , actualCase .State , "\n wanted:" , disputeCaseRecord .OrderState .String ())
684
+ }
685
+ }
686
+
544
687
func TestNotificationsAreReturnedInExpectedOrder (t * testing.T ) {
545
688
const sameTimestampsAreReturnedInReverse = `{
546
689
"notifications": [
0 commit comments