Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Detect Cancel Pending Reservation Event in extension_log #875

Merged
merged 9 commits into from
Mar 1, 2020

Conversation

MarkBis415
Copy link
Contributor

Modify ReservationFlowIntegrationTest to assert that the RESERVATION_CANCELLED event is fired when calling reservationApiV2Controller.cancelPendingReservation.
This requires the following to occur:

  1. Add the Extension.js to src/test/resources/
  2. Generate the script
  • As soon as the test starts, prepare the environment by inserting the extension.js to the database
  • Insert as async = true and async = false
  1. Check that the particular event has been fired
  • We would expect that the corresponding event and only this event logged is RESERVATION_CANCELLED

TODO: 4. Clear the extension log table

  • Use the Spring jdbcTemplate update() method to issue a SQL statement similar to: TRUNCATE TABLE table_name;
  • The table is called extension_log

Current behavior
Presence of RESERVATION_CANCELLED log has been asserted. Also, there are always eight rows in the log when we insert two extensions (one async and one sync). The test still fails due to the following:

19:56:45.789 [Test worker] WARN  alfio.extension.ScriptingExecutionService - hello from script with event: EVENT_CREATED
19:56:45.883 [pool-4-thread-1] WARN  alfio.extension.ScriptingExecutionService - Was not able to compile script asyncName
org.springframework.dao.EmptyResultDataAccessException: Incorrect result size: expected 1, actual 0
…
19:56:46.816 [Test worker] WARN  alfio.extension.ScriptingExecutionService - hello from script with event: EVENT_STATUS_CHANGE
19:56:46.830 [pool-4-thread-1] WARN  alfio.extension.ScriptingExecutionService - Was not able to compile script asyncName
org.springframework.dao.EmptyResultDataAccessException: Incorrect result size: expected 1, actual 0
…
19:56:48.825 [Test worker] WARN  alfio.extension.ScriptingExecutionService - hello from script with event: RESERVATION_VALIDATION
19:56:48.825 [Test worker] WARN  alfio.extension.ScriptingExecutionService - Error while executing script syncName:
com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was STRING at line 1 column 1 path $

On track to close #873.
Contributors: @MarkBis415, @rmace001, @YeeitsAlex

@YeeitsAlex
Copy link
Contributor

Cannot test “cancel pending reservation” because of limitations in the test with running asynchronous extension services. Instead, we have successfully tested an “event created” log, which is a synchronous extension. The next step is to run asynchronous extensions as synchronous during testing. This pull request is ready for review.

Copy link
Member

@cbellone cbellone left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a small error in the extension script (we forgot to cover one case) which is preventing the tests to pass.
Once this small issue is fixed we can merge the pull request

Great Job! Thanks for your contribution!

invoiceNumber: 'blabla'
};
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test is currently failing because we forgot to add here a "return null;" statement to cover all the other Sync events (like RESERVATION_VALIDATION) that expect the script to return something. So this should be:

function executeScript(scriptEvent) {
    log.warn('hello from script with event: ' + scriptEvent);
    extensionLogger.logInfo(scriptEvent);//logs into the extension_log table
    if(scriptEvent === 'INVOICE_GENERATION') {
        return {
            invoiceNumber: 'blabla'
        };
    }
    return null;
}

instead

Co-authored-by: Mark Alexander Bis <35311810+MarkBis415@users.noreply.github.com>
Co-authored-by: Alexander Yee <32520269+YeeitsAlex@users.noreply.github.com>
@cbellone cbellone merged commit bce025e into alfio-event:master Mar 1, 2020
@cbellone
Copy link
Member

cbellone commented Mar 1, 2020

merged. Thanks! 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Detect Cancel Pending Reservation Event in Extension Log Table
4 participants