From ec0cec530a2fa3c7fb6435df047d1b5ae830346e Mon Sep 17 00:00:00 2001 From: Matt Blenkinsop Date: Thu, 13 Feb 2025 15:45:27 +0000 Subject: [PATCH] Bug 38010: (QA follow-up) Add unit tests --- .../integration/Acquisitions/Vendors_spec.ts | 4 +- t/db_dependent/Koha/Acquisition/Booksellers.t | 77 ++++++++++++++++++- 2 files changed, 78 insertions(+), 3 deletions(-) diff --git a/t/cypress/integration/Acquisitions/Vendors_spec.ts b/t/cypress/integration/Acquisitions/Vendors_spec.ts index 013f27d1441..51d4d0f2024 100644 --- a/t/cypress/integration/Acquisitions/Vendors_spec.ts +++ b/t/cypress/integration/Acquisitions/Vendors_spec.ts @@ -94,7 +94,7 @@ describe("Vendor CRUD operations", () => { // Click the button in the toolbar cy.visit("/cgi-bin/koha/vendors"); cy.contains("New vendor").click(); - cy.get("#vendor_add h2").contains("New vendor"); + cy.get("#vendor_add h1").contains("Add vendor"); // Fill in the form for normal attributes cy.get("#vendor_add").contains("Submit").click(); @@ -189,7 +189,7 @@ describe("Vendor CRUD operations", () => { cy.get("#vendors_list table tbody tr:first").contains("Edit").click(); cy.wait("@get-vendor"); cy.wait(500); // Cypress is too fast! Vue hasn't populated the form yet! - cy.get("#vendor_add h2").contains("Edit vendor"); + cy.get("#vendor_add h1").contains("Edit vendor"); // Form has been correctly filled in cy.get("#vendor_name").should("have.value", vendor.name); diff --git a/t/db_dependent/Koha/Acquisition/Booksellers.t b/t/db_dependent/Koha/Acquisition/Booksellers.t index 241663d3d3d..14512113598 100755 --- a/t/db_dependent/Koha/Acquisition/Booksellers.t +++ b/t/db_dependent/Koha/Acquisition/Booksellers.t @@ -17,12 +17,13 @@ use Modern::Perl; -use Test::More tests => 6; +use Test::More tests => 9; use t::lib::TestBuilder; use C4::Acquisition qw( NewBasket ); use C4::Biblio qw( AddBiblio ); +use C4::Contract qw( AddContract ); use C4::Budgets qw( AddBudgetPeriod AddBudget ); use C4::Serials qw( NewSubscription SearchSubscriptions ); @@ -168,6 +169,9 @@ subtest '->contacts() tests' => sub { } ); + # Ensure contacts aren't being duplicated on store + $vendor->contacts( [ $contact_1->unblessed, $contact_2->unblessed ] ); + # Re-fetch vendor $vendor = Koha::Acquisition::Booksellers->find( $vendor->id ); my $contacts = $vendor->contacts; @@ -257,3 +261,74 @@ subtest 'issues' => sub { $schema->storage->txn_rollback(); }; + +subtest 'contracts' => sub { + + plan tests => 2; + + $schema->storage->txn_begin(); + + my $vendor = $builder->build_object( { class => 'Koha::Acquisition::Booksellers' } ); + + is( scalar( @{ $vendor->contracts } ), 0, 'Vendor has no contracts' ); + + AddContract( + { + booksellerid => $vendor->id, + contractname => 'Test contract', + } + ); + + $vendor = $vendor->get_from_storage; + my $contracts = $vendor->contracts; + is( scalar( @{$contracts} ), 1, '1 contract stored' ); + + $schema->storage->txn_rollback(); +}; + +subtest 'invoices' => sub { + + plan tests => 3; + + $schema->storage->txn_begin(); + + my $vendor = $builder->build_object( { class => 'Koha::Acquisition::Booksellers' } ); + + is( $vendor->invoices->count, 0, 'Vendor has no invoices' ); + + Koha::Acquisition::Invoice->new( + { + booksellerid => $vendor->id, + invoicenumber => 'INV12345' + } + )->store; + + $vendor = $vendor->get_from_storage; + my $invoices = $vendor->invoices; + is( $invoices->count, 1, '1 invoice stored' ); + is( ref($invoices), 'Koha::Acquisition::Invoices', 'Type is correct' ); + + $schema->storage->txn_rollback(); +}; + +subtest 'to_api() tests' => sub { + + plan tests => 4; + + $schema->storage->txn_begin; + + my $vendor = $builder->build_object( { class => 'Koha::Acquisition::Booksellers' } ); + + is( $vendor->interfaces->count, 0, 'Vendor has no interfaces' ); + + $vendor->interfaces( + [ { name => 'first interface' }, { name => 'second interface', login => 'one_login', password => 'Test1234' } ] + ); + + my $interfaces = $vendor->to_api->{interfaces}; + is( scalar(@$interfaces), 2, 'Vendor has two interfaces' ); + is( @{$interfaces}[0]->{password}, undef, 'No password set for the interface' ); + is( @{$interfaces}[1]->{password}, 'Test1234', 'password is unhashed' ); + + $schema->storage->txn_rollback; +}; -- 2.48.1