11defmodule Mix.Tasks.StoreRatesTest do
22 use ExUnit.Case
33 use PrisonRideshareWeb.ConnCase
4+ use Bamboo.Test
45
56 alias PrisonRideshare.Repo
67
@@ -22,7 +23,7 @@ defmodule Mix.Tasks.StoreRatesTest do
2223 inserted_at: NaiveDateTime . from_erl! ( { { 2018 , 6 , 24 } , { 16 , 37 , 0 } } )
2324 } )
2425
25- other_price =
26+ ancient_price =
2627 Repo . insert! ( % GasPrice {
2728 price: 5 ,
2829 inserted_at: NaiveDateTime . from_erl! ( { { 2017 , 1 , 1 } , { 0 , 0 , 0 } } )
@@ -40,6 +41,16 @@ defmodule Mix.Tasks.StoreRatesTest do
4041 far: true
4142 } )
4243
44+ _ancient_ride =
45+ Repo . insert! ( % Ride {
46+ start: NaiveDateTime . from_erl! ( { { 2017 , 2 , 2 } , { 11 , 0 , 0 } } ) ,
47+ institution: close_institution ,
48+ end: NaiveDateTime . from_erl! ( { { 2017 , 2 , 2 } , { 12 , 0 , 0 } } ) ,
49+ address: "address" ,
50+ contact: "contact" ,
51+ name: "name"
52+ } )
53+
4354 _old_ride =
4455 Repo . insert! ( % Ride {
4556 start: NaiveDateTime . from_erl! ( { { 2018 , 5 , 23 } , { 11 , 0 , 0 } } ) ,
@@ -95,7 +106,7 @@ defmodule Mix.Tasks.StoreRatesTest do
95106 Repo . insert! ( % Ride {
96107 start: NaiveDateTime . from_erl! ( { { 2018 , 6 , 28 } , { 11 , 0 , 0 } } ) ,
97108 institution: far_institution ,
98- gas_price: other_price ,
109+ gas_price: ancient_price ,
99110 end: NaiveDateTime . from_erl! ( { { 2018 , 6 , 28 } , { 12 , 0 , 0 } } ) ,
100111 address: "address" ,
101112 contact: "contact" ,
@@ -116,6 +127,7 @@ defmodule Mix.Tasks.StoreRatesTest do
116127 Mix.Tasks.StoreRates . run ( [ ] )
117128
118129 [
130+ ancient ,
119131 old ,
120132 yesterday ,
121133 zero_rate_ride ,
@@ -129,7 +141,10 @@ defmodule Mix.Tasks.StoreRatesTest do
129141 |> preload ( :gas_price )
130142 |> Repo . all ( )
131143
132- refute old . gas_price
144+ assert ancient . gas_price . id == ancient_price . id
145+
146+ assert old . gas_price . id == yesterday_price . id
147+ assert old . rate == ~M[ 23]
133148
134149 assert yesterday . gas_price . id == yesterday_price . id
135150 assert yesterday . rate == ~M[ 23]
@@ -140,14 +155,24 @@ defmodule Mix.Tasks.StoreRatesTest do
140155 assert today . gas_price . id == today_price . id
141156 assert today . rate == ~M[ 20]
142157
143- refute tomorrow . gas_price
158+ assert tomorrow . gas_price . id == today_price . id
159+ assert tomorrow . rate == ~M[ 20]
144160
145- assert already_set_gas_price . gas_price . id == other_price . id
161+ assert already_set_gas_price . gas_price . id == ancient_price . id
146162 refute already_set_rate . gas_price
147163
148- [ yesterday_version , _zero_version , _today_version ] = Repo . all ( PaperTrail.Version )
149- assert yesterday_version . event == "update"
150- assert yesterday_version . origin == "StoreRates"
151- assert yesterday_version . item_id == yesterday . id
164+ ancient_version = hd ( Repo . all ( PaperTrail.Version ) )
165+
166+ assert ancient_version . event == "update"
167+ assert ancient_version . origin == "StoreRates"
168+ assert ancient_version . item_id == ancient . id
169+
170+ assert_delivered_email (
171+ PrisonRideshare.Email . store_rates_gap_warning_report ( ancient , ancient_price )
172+ )
173+
174+ assert_delivered_email (
175+ PrisonRideshare.Email . store_rates_gap_warning_report ( old , yesterday_price )
176+ )
152177 end
153178end
0 commit comments