shopware / e2e-testsuite-platform

This package contains the e2e platform test suite for Shopware 6 using Cypress
http://shopware.com
MIT License
20 stars 18 forks source link

BUG: cy.createGuestOrder(product, UserData) & QUESTION: /checkout/register e2e test #21

Closed martijn-bigbridge closed 4 years ago

martijn-bigbridge commented 4 years ago

Using cy.createGuestOrder(product, UserData) will give this error in the latest clean build (shopware) version.

sales-channel-api/v1/checkout/guest-order 400 (Bad Request) VIOLATION::IS_BLANK_ERROR

To fix this problem I hard coded this file: custom/plugins/x/src/Resources/app/storefront/test/e2e/node_modules/@shopware-ag/e2e-testsuite-platform/cypress/support/service/saleschannel/fixture/order.fixture.js

 customerRawData = this.mergeFixtureWithData(customerRawData, {
                    salutationId: salutation.id,
                    billingAddress: {
                        salutationId: salutation.id,
                        countryId: country.id
                    }
                });

Into

 customerRawData = this.mergeFixtureWithData(customerRawData, {
                    salutationId: salutation.id,
                    billingAddress: {
                        salutationId: salutation.id,
                        countryId: country.id,
                        street: 'streetname',
                        zipcode: '1151',
                        city: 'test'
                    }
                });

Then I get the correct data.

But I don't understand how to do e2e test this page /checkout/register 1.) I thought these were the right steps.

But when I do this, I cart is still empty without products.

2.) Or do I need to use some posts (this give the same empty cart problem)

cy.storefrontApiRequest('POST', 'checkout/cart').then((result) => {

3.) Or do I use cypress old school by navigate to the random product url, and search for the "add to cart" button, and than go to the checkout/register page

The full test code at the moment. It would be cool if someone can give a working example.

I'm using 3 fixtures

describe(`Test custom cart`, () => {
    beforeEach(() => {
        cy.getRandomProductInformationForCheckout().then((product) => {

            /* randomProductInformation
            gross: undefined
            id: "e81792a4772d4058bd0d546cdc7f3b3e"
            listingPrice: undefined
            name: "Synergistic Silk Balkan Beef"
            net: undefined
            url: "/detail/e81792a4772d4058bd0d546cdc7f3b3e"
             */

            // This is a empty cart.
            // cy.storefrontApiRequest('POST', 'checkout/cart').then((result) => {
            //     cy.storefrontApiRequest('POST', 'checkout/cart/product/' + product.id, {}, {
            //         type: 'product',
            //         referencedId: product.id,
            //         stackable: true
            //     }).then((result) => {
            //
            //         /* result
            //         affiliateCode: null
            //         campaignCode: null
            //         customerComment: null
            //         deliveries: [{…}]
            //         errors: []
            //         extensions: []
            //         lineItems: [{…}]
            //         modified: false
            //         name: "8a243080f92e4c719546314b577cf82b"
            //         price: {netPrice: 571.43, totalPrice: 680, calculatedTaxes: Array(1), taxRules: Array(1), positionPrice: 680, …}
            //         token: "UukzY0WR2wiBRQR8pWakoCvILrrfci2i"
            //         transactions: [{…}]
            //          */
            //         cy.visit('/checkout/register');
            //     })
            // })

            // this is a empty cart
            cy.createCustomerFixture().then((customer) => {

                /* customer
                attributes: {groupId: "cfbd5018d38d41d8adca10d94fc8bdd6", defaultPaymentMethodId: "ad2b1901d4794969b31cb9b4f887f931", salesChannelId: "9ee6c53d577b456c9aaaea01f9227fbc", languageId: "2fbb5fe2e29a4d70aa5854ce7ce3e20b", lastPaymentMethodId: null, …}
                id: "c4b9353fca2e43819d7b16b9c7c8baa6"
                links: {self: "http://shopware-address-lookup.nl.shopware/api/v1/customer/c4b9353fca2e43819d7b16b9c7c8baa6"}
                meta: null
                relationships: {group: {…}, defaultPaymentMethod: {…}, salesChannel: {…}, language: {…}, lastPaymentMethod: {…}, …}
                type: "customer"
                 */

                return customer
            }).then((customer) => {
             //   console.log(randomProductInformation, customer)

                cy.createGuestOrder(product.id, customer).then( (guestOrder) => {

                    // console.log(guestOrder)
                    /* guestOrder
                    data: {orderNumber: "10066", currencyId: "b7d2554b0ce847cd82f3ac9bd1c0dfca", currencyFactor: 1, salesChannelId: "9ee6c53d577b456c9aaaea01f9227fbc", billingAddressId: "6e0ca916373d42c3a0e6efcd9efd6c57", …}
                    sw-context-token: "FZf3EIG1BJf7cHUEUwgxzjN00dF9CcER"
                     */

                    cy.visit('/checkout/register');
                });
            })

        })
    });

    it('Check things', () => {
        console.log('oke')
    });
});
martijn-bigbridge commented 4 years ago

I see now that createGuestOrder (that was a test) really generates a order in the backend, haha so that is working but one step too far.

I need to see the random product at the cy.visit('/checkout/register'); page

leichteckig commented 4 years ago

Hello @martijn-bigbridge :wave: thank you for your issue and sorry for being late :see_no_evil:

1) Unfortunately, I can't reproduce this issue as the commands work as intended in our tests. Can you provide us more information, e.g. a gist with your full test or similar?

2) If you want to start your test with a full cart, using order commands alone aren't enough. As the context token is not stored in the Storefront session automatically via fixture, you need to write a small handler that writes the context token into the user session.

In our tests, we use the "old school" way as it's part of the workflow the customer would do. You can find our tests in the platform repository.

Well, I hope I was able to help you already, at least a bit. Kind regards, Ramona

martijn-bigbridge commented 4 years ago

Hi @leichteckig,

Thanks for the info.

  1. I guess i'm doing something wrong, I will test this again at a later point.
  2. I will try the 'old school' using your example for now.