-
Notifications
You must be signed in to change notification settings - Fork 8
/
Rakefile
executable file
·140 lines (112 loc) · 3.14 KB
/
Rakefile
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
# frozen_string_literal: true
# rubocop:disable Metrics/MethodLength
require 'rspec/core/rake_task'
require 'dotenv'
require_relative 'lib/fortnox/api'
Dotenv.load('.env.test')
RSpec::Core::RakeTask.new(:spec)
task default: :spec
desc 'Remove all VCR cassettes so we can rerecord them'
task :throw_vcr_cassettes do
FileUtils.rm_rf(Dir.glob('spec/vcr_cassettes/**'))
end
desc 'Seed Fortnox test instane with data required for the test suite'
task :seed_fortnox_test_instance do
Fortnox::API.configure do |config|
config.client_id = ENV.fetch('FORTNOX_API_CLIENT_ID')
config.client_secret = ENV.fetch('FORTNOX_API_CLIENT_SECRET')
config.storage = Class.new do
def access_token
ENV.fetch('FORTNOX_API_ACCESS_TOKEN')
end
def refresh_token; end
def access_token=(token); end
def refresh_token=(token); end
end.new
end
puts 'Seeting Fortnox test instance account with data required for testing...'
seed_customer_data
seed_article_data
seed_invoice_data
seed_order_data
puts 'Done'
end
def seed_customer_data
customer_repository = Fortnox::API::Repository::Customer.new
customer_repository.save(
Fortnox::API::Model::Customer.new(
name: 'A customer from New York',
city: 'New York'
)
)
customer_repository.save(
Fortnox::API::Model::Customer.new(
name: 'Another customer from New York',
city: 'New York',
zip_code: '10001'
)
)
end
def seed_article_data
article_repository = Fortnox::API::Repository::Article.new
article_repository.save(
Fortnox::API::Model::Article.new(
article_number: 101,
description: 'Hammer'
)
)
article_repository.save(
Fortnox::API::Model::Article.new(
article_number: 102,
description: 'Hammer'
)
)
article_repository.save(
Fortnox::API::Model::Article.new(
description: 'Test article'
)
)
article_repository.save(
Fortnox::API::Model::Article.new(
description: 'Test article'
)
)
end
# TODO: When we have support for actions, we should set the states for
# Invoices required by the Invoice Repository spec.
def seed_invoice_data
invoice_repository = Fortnox::API::Repository::Invoice.new
invoice_repository.save(
Fortnox::API::Model::Invoice.new(
customer_number: '1',
your_reference: 'Gandalf the Grey'
)
)
invoice_repository.save(
Fortnox::API::Model::Invoice.new(
customer_number: '1',
your_reference: 'Gandalf the Grey',
our_reference: 'Radagast the Brown'
)
)
end
# TODO: When we have support for actions, we should set the states for
# Order required by the Order Repository spec.
# Also, we should create Orders needed for search tests.
def seed_order_data
order_repository = Fortnox::API::Repository::Order.new
order_repository.save(
Fortnox::API::Model::Order.new(
customer_number: '1',
our_reference: 'Belladonna Took'
)
)
order_repository.save(
Fortnox::API::Model::Order.new(
customer_number: '1',
our_reference: 'Belladonna Took',
your_reference: 'Bodo Proudfoot'
)
)
end
# rubocop:enable Metrics/MethodLength