|
| 1 | +package main |
| 2 | + |
| 3 | +import ( |
| 4 | + "math/rand" |
| 5 | + "strconv" |
| 6 | + |
| 7 | + "github.com/OpenBazaar/openbazaar-go/pb" |
| 8 | + "github.com/golang/protobuf/ptypes/timestamp" |
| 9 | + "github.com/icrowley/fake" |
| 10 | +) |
| 11 | + |
| 12 | +var conditions = []string{"New", "Used", "Bad", "Most Excellent"} |
| 13 | + |
| 14 | +var categories = []string{ |
| 15 | + "Arts", |
| 16 | + "Electronics", |
| 17 | + "Entertainment", |
| 18 | + "Home", |
| 19 | + "Food", |
| 20 | + "Personal", |
| 21 | + "Services", |
| 22 | + "Digital Goods", |
| 23 | + "Other", |
| 24 | +} |
| 25 | + |
| 26 | +func newRandomListing() *pb.ListingReqApi { |
| 27 | + title := fake.ProductName() |
| 28 | + slug := slugify(title) |
| 29 | + sku := slug + "-" + fake.Digits() |
| 30 | + |
| 31 | + tags := make([]string, rand.Intn(9)+1) |
| 32 | + tags[0] = fake.Word() |
| 33 | + for i := 1; i < len(tags); i++ { |
| 34 | + tags[i] = fake.Word() |
| 35 | + } |
| 36 | + |
| 37 | + // Create a random amount of options with random amounts of varients |
| 38 | + options := make([]*pb.Listing_Item_Option, rand.Intn(4)+2) |
| 39 | + for i := 0; i < len(options); i++ { |
| 40 | + options[i] = &pb.Listing_Item_Option{ |
| 41 | + Name: fake.ProductName(), |
| 42 | + Description: fake.Sentence(), |
| 43 | + Variants: make([]*pb.Listing_Item_Option_Variants, rand.Intn(2)+2), |
| 44 | + } |
| 45 | + |
| 46 | + // Ensure description is <= 70 |
| 47 | + if len(options[i].Description) > 70 { |
| 48 | + options[i].Description = options[i].Description[:70] |
| 49 | + } |
| 50 | + |
| 51 | + for j := 0; j < len(options[i].Variants); j++ { |
| 52 | + options[i].Variants[j] = &pb.Listing_Item_Option_Variants{ |
| 53 | + Name: title + " " + fake.ProductName(), |
| 54 | + Image: &pb.Listing_Item_Image{ |
| 55 | + Filename: "example.jpg", |
| 56 | + Original: "QmdfiTnhj1oqiCDmhxu1gdgW6ZqtR7D6ZE7j7CqWUHgKJ8", |
| 57 | + Tiny: "QmbKPEBbzVwax8rnrdxLepfmNkdTqnw2RSfJE19iax3fLK", |
| 58 | + Small: "QmQ77aAsYjs1rxcp7xZ5qUki1RGDGjQ99cok3ynUMF8Sc5", |
| 59 | + Medium: "QmVoh493xbSaKYV9yLtEapaGQ7J31gdCiDQHGSd86PNo8B", |
| 60 | + Large: "QmUWuTZhjUuY8VYWVZrcodsrsbQvckSZwTRxmJ3Avhnw1y", |
| 61 | + }, |
| 62 | + PriceModifier: int64(rand.Intn(50)), |
| 63 | + } |
| 64 | + |
| 65 | + // Ensure name is <= 40 chars |
| 66 | + if len(options[i].Variants[j].Name) > 40 { |
| 67 | + options[i].Variants[j].Name = options[i].Variants[j].Name[:40] |
| 68 | + } |
| 69 | + } |
| 70 | + } |
| 71 | + |
| 72 | + countries := make([]pb.CountryCode, rand.Intn(254)+1) |
| 73 | + for i := 0; i < len(countries); i++ { |
| 74 | + countries[i] = pb.CountryCode(rand.Intn(255)) |
| 75 | + } |
| 76 | + |
| 77 | + return &pb.ListingReqApi{ |
| 78 | + Listing: &pb.Listing{ |
| 79 | + Slug: slug, |
| 80 | + Metadata: &pb.Listing_Metadata{ |
| 81 | + Version: 1, |
| 82 | + AcceptedCurrency: "btc", |
| 83 | + PricingCurrency: "btc", |
| 84 | + Expiry: ×tamp.Timestamp{Seconds: 2147483647}, |
| 85 | + Format: pb.Listing_Metadata_FIXED_PRICE, |
| 86 | + ContractType: pb.Listing_Metadata_ContractType(uint32(rand.Intn(3))), |
| 87 | + }, |
| 88 | + Item: &pb.Listing_Item{ |
| 89 | + Sku: sku, |
| 90 | + Title: title, |
| 91 | + Tags: tags, |
| 92 | + Options: options, |
| 93 | + Nsfw: isNSFW(), |
| 94 | + Description: fake.Paragraphs(), |
| 95 | + Price: uint64(rand.Intn(9999)), |
| 96 | + ProcessingTime: strconv.Itoa(rand.Intn(14)+1) + " days", |
| 97 | + Categories: []string{categories[rand.Intn(len(categories))]}, |
| 98 | + Grams: float32(rand.Intn(5000)), |
| 99 | + Condition: conditions[rand.Intn(len(conditions))], |
| 100 | + Images: []*pb.Listing_Item_Image{ |
| 101 | + { |
| 102 | + Filename: "example.jpg", |
| 103 | + Original: "QmdfiTnhj1oqiCDmhxu1gdgW6ZqtR7D6ZE7j7CqWUHgKJ8", |
| 104 | + Tiny: "QmbKPEBbzVwax8rnrdxLepfmNkdTqnw2RSfJE19iax3fLK", |
| 105 | + Small: "QmQ77aAsYjs1rxcp7xZ5qUki1RGDGjQ99cok3ynUMF8Sc5", |
| 106 | + Medium: "QmVoh493xbSaKYV9yLtEapaGQ7J31gdCiDQHGSd86PNo8B", |
| 107 | + Large: "QmUWuTZhjUuY8VYWVZrcodsrsbQvckSZwTRxmJ3Avhnw1y", |
| 108 | + }, |
| 109 | + }, |
| 110 | + }, |
| 111 | + ShippingOptions: []*pb.Listing_ShippingOption{ |
| 112 | + { |
| 113 | + Name: "usps", |
| 114 | + Type: pb.Listing_ShippingOption_FIXED_PRICE, |
| 115 | + Regions: countries, |
| 116 | + Services: []*pb.Listing_ShippingOption_Service{ |
| 117 | + { |
| 118 | + Name: "standard", |
| 119 | + Price: uint64(rand.Intn(999)), |
| 120 | + EstimatedDelivery: fake.Digits() + " days", |
| 121 | + }, |
| 122 | + }, |
| 123 | + ShippingRules: &pb.Listing_ShippingOption_ShippingRules{ |
| 124 | + RuleType: pb.Listing_ShippingOption_ShippingRules_FLAT_FEE_QUANTITY_RANGE, |
| 125 | + Rules: []*pb.Listing_ShippingOption_ShippingRules_Rule{ |
| 126 | + { |
| 127 | + MinRange: 0, |
| 128 | + MaxRange: 99999999, |
| 129 | + Price: uint64(rand.Intn(999)), |
| 130 | + }, |
| 131 | + }, |
| 132 | + }, |
| 133 | + }, |
| 134 | + }, |
| 135 | + |
| 136 | + TermsAndConditions: fake.Sentences(), |
| 137 | + RefundPolicy: fake.Sentence(), |
| 138 | + }, |
| 139 | + } |
| 140 | +} |
0 commit comments