@frontend_royalties
@lambda_documents
@documents
@graphql_tax_payment
@lambda_documents_payee
Feature: US Tax Form

  @id_ec38e8c63fdac7ed196aceefc538fa7ecffdf53bca56f71ccc15711eba6a6a42
  Scenario: Add Edit and Remove a W-9 US Tax Form
    Given an orchard employee label_7123_admin_1 for abacus ignoring host override
    When I log in to Abacus silently
    Then I am successfully logged in to Abacus
    And I prepare an abacus account data:
      | Key              | Value                   |
      | companyBrandName | theorchard              |
      | paidBy           | ORCHARD-US              |
      | currency         | USD                     |
      | owner            | orchard                 |
      | paymentMinimum   | 123                     |
      | paymentSchedule  | 45 days after month end |
    And I create 1 new account via API
    # Read-only users do not have access to add or remove tax forms
    Given an orchard employee abacus+readonly_e2e_1@sonymusic-pde.com for Abacus
    When I log in to Abacus silently
    Then I am successfully logged in to Abacus
    And I should be able to search for an account by name with navigation "true"
    Then I should not be able to create or edit tax forms
    # Login as admin user to add tax forms
    Given an orchard employee label_7123_admin_1 for abacus ignoring host override
    When I log in to Abacus silently
    Then I am successfully logged in to Abacus
    And I should be able to search for an account by name with navigation "true"
    And I can add a W-9 tax form
    And I can edit a W-9 tax form
    And I can remove a tax form
    Then I log out of Abacus

  @id_f9f482cc8f82ff97ea0b6c75e73567f5d4b1bfa1ac4d381973e80e6d63aa9708
  Scenario: Reject Tax Form
    Given an orchard employee label_7123_admin_1 for abacus ignoring host override
    When I log in to Abacus
    Then I am successfully logged in to Abacus
    Then I can find account by account name and go to info tab orchard_us
    # This test reuses a single seeded account across scenarios, so the account must be reset to a clean state
    And Prepare the test account tax form state for testing
    Then I can reject the tax form with a note this tax form is not valid
    # Verify rejection notes should be visible in documents
    Given an orchard employee label_6971 for documents
    When I log in to documents
    Then I am successfully logged in to documents
    Then I can see that documents Banking & Tax Settings page works with whitelabel account name orchard_us_test
    And I can see the rejection note this tax form is not valid in documents
    Then I log out of documents
    # Go back to Abacus to add new tax form
    Given an orchard employee label_7123_admin_1 for abacus ignoring host override
    When I log in to Abacus silently
    Then I am successfully logged in to Abacus
    Then I can find account by account name and go to info tab orchard_us
    And I can add new tax form when a new tax form is received
    Then I log out of Abacus

  # Wip this scenario until July 31, 2025 (earliest signed date is Jan 2022), Recheck in Dec 2025
  @wip
  @id_9a61395ade63f7067a4dd306c8963b77b06bb4f4a7f84dbbbda3168f2cbfd662
  Scenario: Expired W-8BEN Tax Form
    # Verify in Documents for an already expired tax form
    Given an orchard employee label_6971 for documents
    When I log in to documents silently
    Then I am successfully logged in to documents
    Then I can see that documents Banking & Tax Settings page works with whitelabel account name orchard_us_test
    # Alert triggers 6 months before expiry (July 31) to prompt tax form update
    And I see an expiration alert in Documents for the tax form's signed date 2021-01-05
    Then I log out of documents
    # Verify in Abacus
    Given an orchard employee label_7123_admin_1 for abacus ignoring host override
    When I log in to Abacus
    Then I am successfully logged in to Abacus
    Then I can find account by account name and go to info tab orchard_us
    And I see an expiration alert in Abacus for the tax form's signed date 2021-01-05
    Then I log out of Abacus

  @id_0c018325c11ff0571e756d31ed67edd9cee057f9f69ed47d427ee94fee57dac3
  Scenario: Add a W-8BEN-E Tax Form
    Given an orchard employee label_7123_admin_1 for abacus ignoring host override
    When I log in to Abacus silently
    Then I am successfully logged in to Abacus
    And I prepare an abacus account data:
      | Key              | Value                   |
      | companyBrandName | theorchard              |
      | paidBy           | ORCHARD-US              |
      | currency         | USD                     |
      | owner            | orchard                 |
      | paymentMinimum   | 123                     |
      | paymentSchedule  | 45 days after month end |
    And I create 1 new account via API
    And I can add a W-8BEN-E tax form with signed date 2023-01-05
    Then The form is added and the expiration date is correctly aligned with the signed date 2023-01-05
    # Read-only users can view tax forms with TIN masked
    Given an orchard employee abacus+readonly_e2e_1@sonymusic-pde.com for Abacus
    When I log in to Abacus silently
    Then I am successfully logged in to Abacus
    And I should be able to search for an account by name with navigation "true"
    Then I should not be able to create or edit tax forms
    And I can view the tax form with TIN masked
