Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion .github/workflows/rails_application-coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ on:
paths:
- "apps/rails_application/Gemfile.lock"
- ".github/workflows/rails_application-coverage.yml"
- "apps/rails_application/test/test_helper.rb"
schedule:
- cron: '0 17 * * *'
jobs:
Expand Down Expand Up @@ -59,8 +60,15 @@ jobs:
ruby-version: ruby-3.4.6
bundler-cache: true
working-directory: apps/rails_application
- name: Prepare test database
run: bin/rails db:test:prepare
working-directory: apps/rails_application
env:
DATABASE_URL: "postgres://postgres:secret@localhost:5432/cqrs-es-sample-with-res_test"
RAILS_ENV: test
- name: Run full mutation testing
run: make -C apps/rails_application mutate
run: RAILS_ENV=test bundle exec mutant run --jobs 1
working-directory: apps/rails_application
env:
DATABASE_URL: "postgres://postgres:secret@localhost:5432/cqrs-es-sample-with-res_test"
RAILS_ENV: test
2 changes: 2 additions & 0 deletions apps/rails_application/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ dev:
@$(MAKE) -j 2 web css

mutate: ## Run full mutation tests
@echo "Preparing test database..."
@RAILS_ENV=test bin/rails db:test:prepare
@echo "Running full mutation tests..."
@RAILS_ENV=test bundle exec mutant run

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,5 +91,37 @@ def test_assigns_store_to_correct_invoice_when_multiple_invoices_exist
assert_equal(store_id_1, invoice_1.store_id)
assert_equal(store_id_2, invoice_2.store_id)
end

def test_returns_nil_when_invoice_exists_in_different_store
event_store = Rails.configuration.event_store
store_id_1 = SecureRandom.uuid
store_id_2 = SecureRandom.uuid
invoice_id = SecureRandom.uuid

event_store.publish(
Invoicing::InvoiceItemAdded.new(
data: {
invoice_id: invoice_id,
product_id: SecureRandom.uuid,
title: "Test Product",
quantity: 1,
unit_price: 100,
vat_rate: { rate: 20, code: "VAT" }
}
)
)

event_store.publish(
Stores::InvoiceRegistered.new(
data: {
store_id: store_id_1,
invoice_id: invoice_id
}
)
)

assert_nil Invoices.find_invoice_in_store(invoice_id, store_id_2)
assert_not_nil Invoices.find_invoice_in_store(invoice_id, store_id_1)
end
end
end
1 change: 1 addition & 0 deletions apps/rails_application/test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ def before_setup

Configuration.new.call(Rails.configuration.event_store, Rails.configuration.command_bus)
@default_store_id = ensure_default_store
cookies[:current_store_id] = @default_store_id
result
end

Expand Down
Loading