@@ -117,19 +117,22 @@ describe('requireQuota middleware:', () => {
117117 } ) ) ;
118118 } ) ;
119119
120- test ( 'should treat past_due subscription as free plan' , async ( ) => {
121- mockSubscriptionRepository . findByOrganization . mockResolvedValue ( { plan : 'starter' , status : 'past_due' } ) ;
122- mockBillingUsageService . get . mockResolvedValue ( { counters : { 'scraps.create' : 3 } } ) ;
123-
124- await requireQuota ( 'scraps' , 'create' ) ( req , res , next ) ;
125-
126- expect ( next ) . not . toHaveBeenCalled ( ) ;
127- expect ( res . status ) . toHaveBeenCalledWith ( 429 ) ;
128- expect ( res . json ) . toHaveBeenCalledWith ( expect . objectContaining ( {
129- type : 'error' ,
130- code : 429 ,
131- } ) ) ;
132- } ) ;
120+ test . each ( [ 'past_due' , 'canceled' , 'unpaid' , 'incomplete' , 'incomplete_expired' , 'paused' ] ) (
121+ 'should treat %s subscription as free plan' ,
122+ async ( status ) => {
123+ mockSubscriptionRepository . findByOrganization . mockResolvedValue ( { plan : 'starter' , status } ) ;
124+ mockBillingUsageService . get . mockResolvedValue ( { counters : { 'scraps.create' : 3 } } ) ;
125+
126+ await requireQuota ( 'scraps' , 'create' ) ( req , res , next ) ;
127+
128+ expect ( next ) . not . toHaveBeenCalled ( ) ;
129+ expect ( res . status ) . toHaveBeenCalledWith ( 429 ) ;
130+ expect ( res . json ) . toHaveBeenCalledWith ( expect . objectContaining ( {
131+ type : 'error' ,
132+ code : 429 ,
133+ } ) ) ;
134+ } ,
135+ ) ;
133136
134137 test ( 'should allow unlimited (Infinity) without checking usage' , async ( ) => {
135138 mockSubscriptionRepository . findByOrganization . mockResolvedValue ( { plan : 'pro' , status : 'active' } ) ;
@@ -173,48 +176,6 @@ describe('requireQuota middleware:', () => {
173176 expect ( next ) . toHaveBeenCalled ( ) ;
174177 } ) ;
175178
176- test ( 'should treat canceled subscription as free plan' , async ( ) => {
177- mockSubscriptionRepository . findByOrganization . mockResolvedValue ( { plan : 'starter' , status : 'canceled' } ) ;
178- mockBillingUsageService . get . mockResolvedValue ( { counters : { 'scraps.create' : 3 } } ) ;
179-
180- await requireQuota ( 'scraps' , 'create' ) ( req , res , next ) ;
181-
182- expect ( next ) . not . toHaveBeenCalled ( ) ;
183- expect ( res . status ) . toHaveBeenCalledWith ( 429 ) ;
184- expect ( res . json ) . toHaveBeenCalledWith ( expect . objectContaining ( {
185- type : 'error' ,
186- code : 429 ,
187- } ) ) ;
188- } ) ;
189-
190- test ( 'should treat unpaid subscription as free plan' , async ( ) => {
191- mockSubscriptionRepository . findByOrganization . mockResolvedValue ( { plan : 'starter' , status : 'unpaid' } ) ;
192- mockBillingUsageService . get . mockResolvedValue ( { counters : { 'scraps.create' : 3 } } ) ;
193-
194- await requireQuota ( 'scraps' , 'create' ) ( req , res , next ) ;
195-
196- expect ( next ) . not . toHaveBeenCalled ( ) ;
197- expect ( res . status ) . toHaveBeenCalledWith ( 429 ) ;
198- expect ( res . json ) . toHaveBeenCalledWith ( expect . objectContaining ( {
199- type : 'error' ,
200- code : 429 ,
201- } ) ) ;
202- } ) ;
203-
204- test ( 'should treat incomplete subscription as free plan' , async ( ) => {
205- mockSubscriptionRepository . findByOrganization . mockResolvedValue ( { plan : 'starter' , status : 'incomplete' } ) ;
206- mockBillingUsageService . get . mockResolvedValue ( { counters : { 'scraps.create' : 3 } } ) ;
207-
208- await requireQuota ( 'scraps' , 'create' ) ( req , res , next ) ;
209-
210- expect ( next ) . not . toHaveBeenCalled ( ) ;
211- expect ( res . status ) . toHaveBeenCalledWith ( 429 ) ;
212- expect ( res . json ) . toHaveBeenCalledWith ( expect . objectContaining ( {
213- type : 'error' ,
214- code : 429 ,
215- } ) ) ;
216- } ) ;
217-
218179 test ( 'should use subscription plan when status is trialing' , async ( ) => {
219180 mockSubscriptionRepository . findByOrganization . mockResolvedValue ( { plan : 'starter' , status : 'trialing' } ) ;
220181 mockBillingUsageService . get . mockResolvedValue ( { counters : { 'scraps.create' : 15 } } ) ;
0 commit comments