|
51 | 51 | describe Patient do |
52 | 52 | describe "associations" do |
53 | 53 | it { should have_many(:archive_reasons) } |
| 54 | + |
| 55 | + describe "#vaccination_records" do |
| 56 | + subject(:vaccination_records) { patient.vaccination_records } |
| 57 | + |
| 58 | + let(:patient) { create(:patient) } |
| 59 | + let(:programme) { create(:programme) } |
| 60 | + let(:kept_vaccination_record) do |
| 61 | + create(:vaccination_record, patient:, programme:) |
| 62 | + end |
| 63 | + let(:discarded_vaccination_record) do |
| 64 | + create(:vaccination_record, :discarded, patient:, programme:) |
| 65 | + end |
| 66 | + |
| 67 | + it { should include(kept_vaccination_record) } |
| 68 | + it { should_not include(discarded_vaccination_record) } |
| 69 | + end |
54 | 70 | end |
55 | 71 |
|
56 | 72 | describe "scopes" do |
|
464 | 480 | it { should normalize(:address_postcode).from(" SW111AA ").to("SW11 1AA") } |
465 | 481 | end |
466 | 482 |
|
467 | | - describe "#vaccination_records" do |
468 | | - subject(:vaccination_records) { patient.vaccination_records } |
| 483 | + describe "#teams" do |
| 484 | + subject(:teams) { patient.teams } |
469 | 485 |
|
470 | 486 | let(:patient) { create(:patient) } |
471 | | - let(:programme) { create(:programme) } |
472 | | - let(:kept_vaccination_record) do |
473 | | - create(:vaccination_record, patient:, programme:) |
474 | | - end |
475 | | - let(:discarded_vaccination_record) do |
476 | | - create(:vaccination_record, :discarded, patient:, programme:) |
477 | | - end |
478 | 487 |
|
479 | | - it { should include(kept_vaccination_record) } |
480 | | - it { should_not include(discarded_vaccination_record) } |
| 488 | + it { should be_empty } |
| 489 | + |
| 490 | + context "when a team exists" do |
| 491 | + let!(:team) { create(:team) } |
| 492 | + |
| 493 | + it { should be_empty } |
| 494 | + |
| 495 | + context "and the patient belongs to the team" do |
| 496 | + let(:session) { create(:session, team:) } |
| 497 | + let(:patient) { create(:patient, session:) } |
| 498 | + |
| 499 | + it { should include(team) } |
| 500 | + end |
| 501 | + |
| 502 | + context "and the patient belongs to multiple sessions under the same team" do |
| 503 | + let(:menacwy_session) do |
| 504 | + create(:session, team:, programmes: [create(:programme, :menacwy)]) |
| 505 | + end |
| 506 | + let(:td_ipv_session) do |
| 507 | + create(:session, team:, programmes: [create(:programme, :td_ipv)]) |
| 508 | + end |
| 509 | + let(:patient) { create(:patient, session: menacwy_session) } |
| 510 | + |
| 511 | + before { create(:patient_location, patient:, session: td_ipv_session) } |
| 512 | + |
| 513 | + it { should contain_exactly(team) } |
| 514 | + end |
| 515 | + end |
481 | 516 | end |
482 | 517 |
|
483 | 518 | describe "#match_existing" do |
|
0 commit comments