Code Monkey home page Code Monkey logo

Comments (1)

danielecr avatar danielecr commented on June 3, 2024

I found a way.
First of all the host must be setted, and currently documentation does not provide any details about amazonMws.setHost() call
There is no information about setContentType() also ...

There are a lot of set[thing]() method, but there is no setSocket() function, I would like to use amazonMws.setSocket(http), or amazonMws.setSocket(httpmock), and provide some mock for testing. I found something good in this code, but unit tests are not real unit test, the .spec.js test everything from request to the end of handling of response, that is generally called functional tests.

To split those parts the code should be splitted from AmazonMwsResource.js, and really that source file is too much big.

@bhushankumarl , You ask to contributor to run all tests before making a pull request, but the tests must be ran against a real alive amazon api, and this is a real problem if you want the tests to be automatic (you should inject SellerId, auth key, private key, ... and where does the automatic test get this data?)

Tests must be automatic, so tests as of now are not usable.

There are a number of option to mock http, like nock, https://github.com/nock/nock, I do not know it, but maybe there are other things that could be used.

OK. I Stop here the code review. I come back to "how to submit document":

        let host = hostbycountry(PlatformCountry);
        amazonMws.setHost(host);
        amazonMws.setContentType('application/octet-stream');
        const mwsRequestData = {
            Version: '2009-01-01',
            Action: 'SubmitFeed',
            FeedType: '_UPLOAD_VAT_INVOICE_',
            PurgeAndReplace: 'false',
            FeedContent: docData,
            SellerId: 'merchantid',
            MWSAuthToken: 'mws_auth_token',
            'MarketplaceIdList.Id.1': 'marketplaceid',
            FeedOptions: 'metadata:orderid=....'
        };
        return amazonMws.feeds.submit(mwsRequestData)

Something to note:

  • SellerId and Merchant are synonyms.
  • PurgeAndReplace is a string
  • FeedOptions is a string in the format specified in https://m.media-amazon.com/images/G/03/B2B/invoice-uploader-developer-documentation.pdf
  • hostbycountry() here is a function that return the host as listed in https://docs.developer.amazonservices.com/en_US/dev_guide/DG_Endpoints.html , by the country code of the merchant (the sellerId), not the marketplace! this means that the SellerId and AuthToken is paired with the platform, even if the merchant is selling in another country, but MarketplaceIdList.Id.1 is the marketplace where the order is placed (where the good was sold).
  • amazonMws.setContentType('application/octet-stream'), because it is not an 'x-www-form-urlencoded', it is an upload instead, this should be automatic, maybe, but I solved it without touching the code

from amazon-mws.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.