|
4 | 4 | let(:lat) { 37.32 } |
5 | 5 | let(:lon) { 122.03 } |
6 | 6 | let(:path) { "/weather/en/#{lat}/#{lon}" } |
7 | | - let(:data_sets) { [Tenkit::Utils.snake(data_set).to_sym] } |
8 | | - let(:query) { {query: {dataSets: data_set}} } |
9 | | - |
| 7 | + let(:params) { {dataSets: data_set} } |
10 | 8 | let(:client) { Tenkit::Client.new } |
11 | | - let(:api_response) { double("WeatherResponse", body: json) } |
12 | 9 | let(:json) { File.read("test/fixtures/#{data_set}.json") } |
| 10 | + let(:resp) { double("WeatherResponse", body: json) } |
| 11 | + let(:data_sets) { [Tenkit::Utils.snake(data_set).to_sym] } |
13 | 12 |
|
14 | | - before { allow(client).to receive(:get).and_return(api_response) } |
| 13 | + before { expect(client).to receive(:get).with(path, {query: params}).and_return(resp) } |
15 | 14 |
|
16 | 15 | describe "currentWeather" do |
17 | 16 | let(:data_set) { "currentWeather" } |
18 | 17 |
|
19 | | - subject { client.weather(lat, lon, data_sets: data_sets).weather.current_weather } |
| 18 | + context "with options" do |
| 19 | + let(:fmt) { "%FT%TZ" } |
| 20 | + let(:now) { Time.now } |
| 21 | + let(:options) do |
| 22 | + {country_code: "US", |
| 23 | + current_as_of: now.strftime(fmt), |
| 24 | + daily_end: (now + 12 * 3600).strftime(fmt), |
| 25 | + daily_start: (now - 12 * 3600).strftime(fmt), |
| 26 | + data_sets: data_sets, |
| 27 | + hourly_end: (now + 6 * 3600).strftime(fmt), |
| 28 | + hourly_start: (now - 6 * 3600).strftime(fmt), |
| 29 | + timezone: "PST"} |
| 30 | + end |
| 31 | + let(:params) do |
| 32 | + options.map { |k, v| [Tenkit::Utils.camel(k.to_s).to_sym, (k == :data_sets) ? data_set : v] }.to_h |
| 33 | + end |
20 | 34 |
|
21 | | - it "returns response from correct data_sets" do |
22 | | - subject |
23 | | - expect(client).to have_received(:get).with(path, query) |
24 | | - end |
| 35 | + subject { client.weather(lat, lon, **options).weather.current_weather } |
25 | 36 |
|
26 | | - it "includes expected metadata" do |
27 | | - expect(subject.name).to eq "CurrentWeather" |
28 | | - expect(subject.metadata.attribution_url).to start_with 'https://' |
29 | | - expect(subject.metadata.latitude).to be 37.32 |
30 | | - expect(subject.metadata.longitude).to be 122.03 |
31 | | - end |
| 37 | + it "includes expected metadata" do |
| 38 | + expect(subject.name).to eq "CurrentWeather" |
| 39 | + expect(subject.metadata.attribution_url).to start_with "https://" |
| 40 | + expect(subject.metadata.latitude).to be 37.32 |
| 41 | + expect(subject.metadata.longitude).to be 122.03 |
| 42 | + end |
32 | 43 |
|
33 | | - it "returns correct object types" do |
34 | | - expect(subject).to be_a Tenkit::CurrentWeather |
35 | | - expect(subject.metadata).to be_a Tenkit::Metadata |
36 | | - end |
| 44 | + it "returns correct object types" do |
| 45 | + expect(subject).to be_a Tenkit::CurrentWeather |
| 46 | + expect(subject.metadata).to be_a Tenkit::Metadata |
| 47 | + end |
37 | 48 |
|
38 | | - it "returns current weather data" do |
39 | | - expect(subject.temperature).to be(-5.68) |
40 | | - expect(subject.temperature_apparent).to be(-6.88) |
| 49 | + it "returns current weather data" do |
| 50 | + expect(subject.temperature).to be(-5.68) |
| 51 | + expect(subject.temperature_apparent).to be(-6.88) |
| 52 | + end |
41 | 53 | end |
42 | 54 |
|
43 | 55 | context "without options" do |
44 | 56 | subject { client.weather(lat, lon).weather.current_weather } |
45 | 57 |
|
46 | | - it "returns response from default currentWeather data set" do |
| 58 | + it "returns response" do |
47 | 59 | expect(subject.name).to eq "CurrentWeather" |
48 | | - expect(client).to have_received(:get).with(path, query) |
49 | 60 | end |
50 | 61 | end |
51 | 62 | end |
|
56 | 67 |
|
57 | 68 | subject { client.weather(lat, lon, data_sets: data_sets).weather.forecast_daily } |
58 | 69 |
|
59 | | - it "returns 10 days of data from correct data sets" do |
| 70 | + it "returns 10 days of data" do |
60 | 71 | expect(subject.days.size).to be 10 |
61 | | - expect(client).to have_received(:get).with(path, query) |
62 | 72 | end |
63 | 73 |
|
64 | 74 | it "returns correct object types" do |
|
69 | 79 | expect(first_day.rest_of_day_forecast).to be_a Tenkit::RestOfDayForecast |
70 | 80 | end |
71 | 81 |
|
72 | | - it "excludes learn_more_url node" do |
73 | | - expect(subject.respond_to? :learn_more_url).to be false |
74 | | - end |
75 | | - |
76 | 82 | it "includes expected metadata" do |
77 | 83 | expect(subject.name).to eq "DailyForecast" |
78 | | - expect(subject.metadata.attribution_url).to start_with 'https://' |
| 84 | + expect(subject.metadata.attribution_url).to start_with "https://" |
79 | 85 | expect(subject.metadata.latitude).to be 37.32 |
80 | 86 | expect(subject.metadata.longitude).to be 122.03 |
81 | 87 | end |
|
101 | 107 |
|
102 | 108 | subject { client.weather(lat, lon, data_sets: data_sets).weather.forecast_hourly } |
103 | 109 |
|
104 | | - it "returns 25 hours of data from correct data sets" do |
| 110 | + it "returns 25 hours of data" do |
105 | 111 | expect(subject.hours.size).to be 25 |
106 | | - expect(client).to have_received(:get).with(path, query) |
107 | 112 | end |
108 | 113 |
|
109 | 114 | it "includes expected metadata" do |
110 | 115 | expect(subject.name).to eq "HourlyForecast" |
111 | | - expect(subject.metadata.attribution_url).to start_with 'https://' |
| 116 | + expect(subject.metadata.attribution_url).to start_with "https://" |
112 | 117 | expect(subject.metadata.latitude).to be 37.32 |
113 | 118 | expect(subject.metadata.longitude).to be 122.03 |
114 | 119 | end |
|
0 commit comments