Open danielecr opened 3 years ago
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 stringFeedOptions
is a string in the format specified in https://m.media-amazon.com/images/G/03/B2B/invoice-uploader-developer-documentation.pdfhostbycountry()
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
rif. #116
Describe the bug Document upload does not work
please reopen #116
the url is wrong. The api reply user not allowed. See #116
Which Amazon MWS Marketplace are you using? All
Most Important, Is this working with the Amazon Scratchpad? not testable.
Add you Amazon MWS Request
What Response are you receiving?