in reply to Re^3: [RFC] Module code and POD for CPAN
in thread [RFC] Module code and POD for CPAN
The documentation has now been updated taking into consideration all the feedback people have kindly provided.
I've gone through the documentation and written several tests for each method. Some time ago I read an article about writing tests and cannot find it now. But the one thing that stood out from it was to start writing tests based on the documentation...so that is about what I have done. However, I cannot see a way to test getting an intent as that requires a valid API key. Something that will not be available to the installation scripts. So I have called the method and checked that the success method returns false. Is there a better way to handle the lack of API key?
This has generated some more questions:
There are 30 tests I have created but gmake test says there are 31. Does diag count as a test or does something else account for the discrepancy?
If plan tests => 31 is included I get the error Parse errors: Plan (1..31) must be at the beginning or end of the TAP output. However, plan tests => 31 was autogenerated. I have to use Test::More tests => 31; to get rid of the error. I cannot find any explanation of the error so what does it actually mean?
Are there any other glaringly obvious tests that should be included, but that have been left out?
00-load.t
#!perl use 5.006; use strict; use warnings; use Test::More tests => 31; #my $test_count = 31; #plan tests => $test_count; BEGIN { use_ok( 'Business::Stripe::WebCheckout' ) || print "Bail out!\n"; } diag( "Testing Business::Stripe::WebCheckout $Business::Stripe::WebChe +ckout::VERSION, Perl $], $^X" ); my $stripe = Business::Stripe::WebCheckout->new( 'api-public' => 'pk_test_00000000000000000000000000000000000000 +000000000000000000000000000000000000000000000000000000000', 'api-secret' => 'sk_test_00000000000000000000000000000000000000 +000000000000000000000000000000000000000000000000000000000', 'success-url' => 'https://www.example.com/yippee.html', 'cancel-url' => 'https://www.example.com/ohdear.html', ); ok( $stripe->isa( 'Business::Stripe::WebCheckout' ), 'Instantiation' ) +; ok( $stripe->success, 'Successful obje +ct creation' ); ok( scalar( $stripe->list_products ) == 0, 'Empty Trolley' + ); $stripe->add_product( 'id' => 'A', 'name' => 'One', 'description' => 'Test One', 'qty' => 1, 'price' => 100, ); ok( scalar( $stripe->list_products ) == 1, + 'First product added to Trolley' ); ok( $stripe->get_product(($stripe->list_products)[0])->{'id'} + eq 'A', 'Correct Product A ID' ); ok( $stripe->get_product(($stripe->list_products)[0])->{'name'} + eq 'One', 'Correct Product A Name' ); ok( $stripe->get_product(($stripe->list_products)[0])->{'description'} + eq 'Test One', 'Correct Product A Description' ); ok( $stripe->get_product(($stripe->list_products)[0])->{'qty'} + eq '1', 'Correct Product A Quantity' ); ok( $stripe->get_product(($stripe->list_products)[0])->{'price'} + eq '100', 'Correct Product A Price' ); $stripe->add_product( 'id' => 'B', 'name' => 'Two', 'description' => 'Test Two', 'qty' => 2, 'price' => 200, ); ok( scalar( $stripe->list_products ) == 2, + 'Second product added to Trolley' ); ok( $stripe->get_product(($stripe->list_products)[1])->{'id'} + eq 'B', 'Correct Product B ID' ); ok( $stripe->get_product(($stripe->list_products)[1])->{'name'} + eq 'Two', 'Correct Product B Name' ); ok( $stripe->get_product(($stripe->list_products)[1])->{'description'} + eq 'Test Two', 'Correct Product B Description' ); ok( $stripe->get_product(($stripe->list_products)[1])->{'qty'} + eq '2', 'Correct Product B Quantity' ); ok( $stripe->get_product(($stripe->list_products)[1])->{'price'} + eq '200', 'Correct Product B Price' ); $stripe->add_product( 'id' => 'C', 'name' => 'Three', 'description' => 'Test Three', 'qty' => 3, 'price' => 300, ); ok( scalar( $stripe->list_products ) == 3, + 'Third product added to Trolley' ); ok( $stripe->get_product(($stripe->list_products)[2])->{'id'} + eq 'C', 'Correct Product C ID' ); ok( $stripe->get_product(($stripe->list_products)[2])->{'name'} + eq 'Three', 'Correct Product C Name' ); ok( $stripe->get_product(($stripe->list_products)[2])->{'description'} + eq 'Test Three','Correct Product C Description' ); ok( $stripe->get_product(($stripe->list_products)[2])->{'qty'} + eq '3', 'Correct Product C Quantity' ); ok( $stripe->get_product(($stripe->list_products)[2])->{'price'} + eq '300', 'Correct Product C Price' ); $stripe->delete_product('B'); ok( $stripe->success, + 'Product removed from Trolley' ); ok( scalar( $stripe->list_products ) == 2, + 'Product count correct after removal' ); $stripe->delete_product('B'); ok( !$stripe->success, + 'Cannot remove product from Trolley that isn\' +t there' ); $stripe->delete_product('A'); ok( $stripe->success, + 'Another product removed from Trolley' ); ok( scalar( $stripe->list_products ) == 1, + 'Product count again correct after removal' ); my $intent = $stripe->get_intent; ok ( !$stripe->success, + 'Failed to get intent as invalid key' ); my $intent_id = $stripe->get_intent_id; ok ( !$stripe->success, + 'Failed to get intent_id as invalid key' ); my $ids = $stripe->get_ids; ok ( !$stripe->success, + 'Failed to get ids as invalid key' ); my $checkout = $stripe->checkout; ok ( !$stripe->success, + 'Failed to generate checkout HTML as invalid + key' ); # done_testing($test_count);
Also just to note in case anyone else finds this in future - the environment variable (on Strawberry Perl at least) is RELEASE_TESTING and not AUTHOR_TESTING
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^5: [RFC] Module code and POD for CPAN - Testing env vars
by hippo (Archbishop) on Apr 16, 2021 at 08:51 UTC | |
Re^5: [RFC] Module code and POD for CPAN - Testing and test file
by choroba (Cardinal) on Apr 16, 2021 at 06:55 UTC | |
by Bod (Parson) on Apr 16, 2021 at 19:40 UTC | |
Re^5: [RFC] Module code and POD for CPAN - Testing and test file
by hippo (Archbishop) on Apr 15, 2021 at 22:02 UTC | |
by Bod (Parson) on Apr 16, 2021 at 14:26 UTC |