-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfake.rb
More file actions
142 lines (118 loc) · 3.79 KB
/
Copy pathfake.rb
File metadata and controls
142 lines (118 loc) · 3.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
# frozen_string_literal: true
module IntelligentFoods
module Testing
class Fake
def self.configure(*); end
class Allergen
def self.new(code: "MILK", source: "ANCHOVY")
OpenStruct.new(code: code, source: source)
end
end
class DistributionCenterInventory
def self.create(name: "WEST_COAST", quantity: 100)
OpenStruct.new(distribution_center: name, quantity: quantity)
end
end
class InventoryLevel
def self.create(sku: "SKU1", date: Date.today.to_s,
dc_inventory: [DistributionCenterInventory.create])
inventory_level = OpenStruct.new(
date: date,
inventory_by_distribution_center: dc_inventory
)
OpenStruct.new(sku: sku, inventory_levels: [inventory_level])
end
end
class MenuItem
def self.create(id: SecureRandom.uuid, sku: "SKU1",
name: "FakeMenuItem")
OpenStruct.new(id: id, sku: sku, name: name)
end
end
class Menu
def self.new(id: Date.today.to_s)
items = [Fake::MenuItem.create]
OpenStruct.new(id: id, deadline: Time.zone.now,
shipping_fee: 9.99, items: items)
end
def self.retrieve(id)
items = [Fake::MenuItem.create]
OpenStruct.new(id: id, deadline: Time.zone.now,
shipping_fee: 9.99, items: items)
end
end
class MenuItemSerializer
def initialize(menu_item)
OpenStruct.new(id: menu_item.id, sku: menu_item.sku,
name: menu_item.name)
end
end
class Recipient
def self.new(name: nil, street1: nil, street2: nil, city: nil,
state: nil, zip: nil, zip4: nil, email: nil, phone: nil,
delivery_instructions: nil)
OpenStruct.new(name: name, street1: street1, street2: street2,
city: city, state: state, zip: zip, zip4: zip4,
email: email, phone: phone,
delivery_instructions: delivery_instructions)
end
end
class Order
def initialize(*)
self
end
def id
@id ||= SecureRandom.uuid
end
def create!
items = [Fake::MenuItem.create]
ship_to = Fake::Recipient.new
OpenStruct.new(id: SecureRandom.uuid, items: items,
ship_to: ship_to)
end
def cancel!
OpenStruct.new(id: SecureRandom.uuid,
status: "CANCELLED")
end
end
class OrderItem
def self.new(sku:, quantity:, protein_sku:)
OpenStruct.new(sku: sku, quantity: quantity, protein_sku: protein_sku)
end
end
class Product
def self.new(code:, name:, status: "DRAFT", nutrition_facts: [])
OpenStruct.new(code: code, name: name, status: status,
nutrition_facts: nutrition_facts,
allergens: [Fake::Allergen.new],
dietary_tags: ["NUTS"])
end
end
def self.client
Fake::Client.new
end
class ApiClient
def self.new(*)
Fake::Client.new
end
end
class ApiClientSerializer
def self.serialize(*)
OpenStruct.new(id: nil, secret: nil).to_h
end
end
class Client
def initialize(*)
self
end
def authenticated?
false
end
def authenticate!; end
end
class OrderNotCreatedError < StandardError; end
class OrderNotCancelledError < StandardError; end
class AuthenticationError < StandardError; end
end
end
end