You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
require'rspec'require'active_record'require'date'# Assuming the necessary models and the function are already defined and available# For example:# class Customer < ActiveRecord::Base# has_many :projects# end## class Project < ActiveRecord::Base# enum workflow_state: { in_progress: 0, completed: 1, pending: 2 }# endRSpec.describe'in_progress_projects'dolet(:customer){Customer.create}let(:last_month){Date.today.prev_month}beforedo# Clean up the database before each testProject.delete_allCustomer.delete_allendcontext'Basic Functionality'doit'returns projects in progress created after last_month'doproject1=customer.projects.create(workflow_state: 'in_progress',created_at: Date.today)project2=customer.projects.create(workflow_state: 'completed',created_at: Date.today)project3=customer.projects.create(workflow_state: 'in_progress',created_at: last_month - 1)result=in_progress_projects(customer,last_month)expect(result).tocontain_exactly(project1.id)endit'returns an empty list when no projects are in progress'docustomer.projects.create(workflow_state: 'completed',created_at: Date.today)result=in_progress_projects(customer,last_month)expect(result).tobe_emptyendendcontext'Edge Cases'doit'returns an empty list when all projects are created before last_month'docustomer.projects.create(workflow_state: 'in_progress',created_at: last_month - 1)result=in_progress_projects(customer,last_month)expect(result).tobe_emptyendit'returns an empty list when projects are created exactly on last_month'docustomer.projects.create(workflow_state: 'in_progress',created_at: last_month)result=in_progress_projects(customer,last_month)expect(result).tobe_emptyendit'returns an empty list when customer has no projects'doresult=in_progress_projects(customer,last_month)expect(result).tobe_emptyendendcontext'Error Conditions'doit'raises an error with invalid date for last_month'doexpect{in_progress_projects(customer,'invalid_date')}.toraise_error(ArgumentError)endit'raises an error with null customer'doexpect{in_progress_projects(nil,last_month)}.toraise_error(NoMethodError)endendcontext'Performance and Scale'doit'handles a large number of projects efficiently'do1000.timesdocustomer.projects.create(workflow_state: 'in_progress',created_at: Date.today)endresult=in_progress_projects(customer,last_month)expect(result.size).toeq(1000)endendcontext'Special Cases'doit'returns projects with future creation dates'dofuture_project=customer.projects.create(workflow_state: 'in_progress',created_at: Date.today + 1)result=in_progress_projects(customer,last_month)expect(result).tocontain_exactly(future_project.id)endit'returns only projects associated with the given customer'doother_customer=Customer.createshared_project=customer.projects.create(workflow_state: 'in_progress',created_at: Date.today)other_customer.projects << shared_projectresult=in_progress_projects(customer,last_month)expect(result).tocontain_exactly(shared_project.id)endendcontext'Additional Test Cases'doit'returns only the correct projects with mixed states and dates'doproject1=customer.projects.create(workflow_state: 'in_progress',created_at: Date.today)project2=customer.projects.create(workflow_state: 'completed',created_at: Date.today)project3=customer.projects.create(workflow_state: 'in_progress',created_at: last_month - 1)result=in_progress_projects(customer,last_month)expect(result).tocontain_exactly(project1.id)endit'handles boundary test for last_month correctly'doboundary_project=customer.projects.create(workflow_state: 'in_progress',created_at: last_month + 1)result=in_progress_projects(customer,last_month)expect(result).tocontain_exactly(boundary_project.id)endendend
The text was updated successfully, but these errors were encountered:
Unit Test Coverage for " senza-lnd.check_enqueued_projects_worker.in_progress_projects"
Stakwork Run
Unit Test Code
The text was updated successfully, but these errors were encountered: