@@ -25,8 +25,8 @@ describe('Auths cache', function()
2525
2626 cache :set (transaction , auth_status )
2727
28- local cached = cache :get (transaction )
29- assert .equals (auth_status , cached . status )
28+ local cached_status = cache :get (transaction )
29+ assert .equals (auth_status , cached_status )
3030 end )
3131
3232 it (' caches auth with app id + app key' , function ()
@@ -35,8 +35,8 @@ describe('Auths cache', function()
3535
3636 cache :set (transaction , auth_status )
3737
38- local cached = cache :get (transaction )
39- assert .equals (auth_status , cached . status )
38+ local cached_status = cache :get (transaction )
39+ assert .equals (auth_status , cached_status )
4040 end )
4141
4242 it (' caches auth with access token' , function ()
@@ -45,8 +45,8 @@ describe('Auths cache', function()
4545
4646 cache :set (transaction , auth_status )
4747
48- local cached = cache :get (transaction )
49- assert .equals (auth_status , cached . status )
48+ local cached_status = cache :get (transaction )
49+ assert .equals (auth_status , cached_status )
5050 end )
5151
5252 it (' caches auths with same usages but different order in the same key' , function ()
@@ -65,8 +65,8 @@ describe('Auths cache', function()
6565
6666 cache :set (transaction_with_order_1 , auth_status )
6767
68- local cached = cache :get (transaction_with_order_2 )
69- assert .equals (auth_status , cached . status )
68+ local cached_status = cache :get (transaction_with_order_2 )
69+ assert .equals (auth_status , cached_status )
7070 end )
7171
7272 it (' caches a rejection reason when given' , function ()
@@ -77,15 +77,54 @@ describe('Auths cache', function()
7777
7878 cache :set (transaction , not_authorized_status , rejection_reason )
7979
80- local cached = cache :get (transaction )
81- assert .equals (not_authorized_status , cached . status )
82- assert .equals (rejection_reason , cached . rejection_reason )
80+ local cached_status , cached_rejection_reason = cache :get (transaction )
81+ assert .equals (not_authorized_status , cached_status )
82+ assert .equals (rejection_reason , cached_rejection_reason )
8383 end )
8484
8585 it (' returns nil when something is not cached' , function ()
8686 local user_key = { user_key = ' uk' }
8787 local transaction = Transaction .new (service_id , user_key , usage )
88+
8889
8990 assert .is_nil (cache :get (transaction ))
9091 end )
92+
93+ it (' returns status without rejection_reason when cached without one' , function ()
94+ local user_key = { user_key = ' uk' }
95+ local transaction = Transaction .new (service_id , user_key , usage )
96+
97+ cache :set (transaction , auth_status )
98+
99+ local cached_status , cached_rejection_reason = cache :get (transaction )
100+ assert .equals (auth_status , cached_status )
101+ assert .is_nil (cached_rejection_reason )
102+ end )
103+
104+ it (' parses rejection reason containing colons' , function ()
105+ local app_id_and_key = { app_id = ' an_id' , app_key = ' a_key' }
106+ local transaction = Transaction .new (service_id , app_id_and_key , usage )
107+ local rejection_reason = ' reason:with:colons'
108+
109+ cache :set (transaction , 409 , rejection_reason )
110+
111+ local cached_status , cached_rejection_reason = cache :get (transaction )
112+ assert .equals (409 , cached_status )
113+ assert .equals (rejection_reason , cached_rejection_reason )
114+ end )
115+
116+ it (' returns correct status for different HTTP status codes' , function ()
117+ local user_key = { user_key = ' uk' }
118+
119+ for _ , status_code in ipairs ({ 200 , 403 , 404 , 409 , 500 }) do
120+ local tx_usage = Usage .new ()
121+ tx_usage :add (' m_' .. status_code , 1 )
122+ local transaction = Transaction .new (service_id , user_key , tx_usage )
123+
124+ cache :set (transaction , status_code )
125+
126+ local cached_status , cached_rejection_reason = cache :get (transaction )
127+ assert .equals (status_code , cached_status )
128+ end
129+ end )
91130end )
0 commit comments