Skip to content

Latest commit

 

History

History
 
 

avatax

Saleor AvaTax App

Saleor App AvaTax

Connect your dynamic taxes calculation to AvaTax API.

Documentation

Visit AvaTax App documentation to learn how to configure and develop the app locally.

Testing

E2E tests

Our E2E tests are using PactumJS for making requests to Saleor instance and a separate Vitest workspace for running tests.

Before running tests, you have to set up .env file with TEST_SALEOR_API_URL that points to your Saleor instance with installed AvaTax app. For reference, you can use .env.example file:

cp .env.example .env

You should also add E2E_USER_NAME and E2E_USER_PASSWORD which are credentials for a staff user that has permissions of MANAGE_ORDERS.

You also have to generate GraphQL files using graphql-codegen:

pnpm run generate

Running tests

After you complete the setup, run the tests with:

pnpm run e2e

Saleor instance requirements

Our tests include default data that is used for our specific Saleor instance. It includes IDs of products, channels, vouchers, etc. You can find them in e2e/data/maps and e2e/data/templates.

If you want to create a new instance from scratch, you have to create a fork of this repository and create following configuration in your Saleor:

  • Channels
    • Create USA channel with USD currency and United States as country, the channel should have orderSettings: allowUnpaidOrders: true, automaticallyConfirmAllNewOrders: true
  • Warehouse: create new warehouse or use existing ones and set-up shipping methods for your new channel
  • Tax classes: create each tax class for test case used in our tests (see e2e/data/maps/product.json)
  • Products
    • Create or use existing products (from default saleor-platform seed data) and assign them tax class and make them available in USA channel
  • Tax configuration: Set USA channel tax configuration ot tax app and pricesEnteredWithTax: false
  • App: Install AvaTax app and configure it with your account, assign shipping address in USA, and set up tax classes for products

Bruno

Bruno is an open source tool for exploring and testing APIs. It's similar to Postman or Insomnia.

This app has a collection of requests to Saleor that go through fetching a product from channel, creating a checkout, adding shipping method and completing checkout (channel must have allowUnpaidOrders setting set to true). You also need to set enableAccountConfirmationByEmail to false in your shop site settings.

To set up Bruno, go to the bruno directory and run

pnpm install --ignore-workspace

After that, you have to prepare an environment for Bruno. Environments are a set of variables that are used in requests.

To use your own storefront user create .env file inside bruno folder with:

STOREFRONT_USER_EMAIL=
STOREFRONT_USER_PASSWORD=
STOREFRONT_USER_NAME=

The app has an example environment for localhost in environments/localhost.bru. You can copy it to bootstrap your own environment e.g cloud.bru (which will be ignored by git).

Webhook migration scripts

Note

This section refers to apps hosted by Saleor or using REST APL. If you self host AvaTax app you need to write your own logic for updating migration scripts. See How to update app webhooks for more info.

You need to set REST_APL_TOKEN & REST_APL_ENDPOINT in our .env file first. Set DANGEROUS_ENABLE_MIGRATION_CONSOLE_LOGGER to see migration results in your shell.

Test migration with dry run, operation will not modify any data:

pnpm migrate:dry-run

To start the migration run command:

pnpm migrate

Running the app in docker

To run the app in docker, you need to build the image first (run this command in the root directory of the monorepo):

docker build --tag saleor-app-avatax-docker --file Dockerfile.avatax.dev .

Then you can run the image (run this command in the root directory of the monorepo):

docker run -p 3000:3000 --env-file apps/avatax/.env saleor-app-avatax-docker