Getting ExpectationError: Unexpected call: get('URL_here') when trying to mock Axios API in Sinon - api

I am trying to mock the third-party API calls in mocha-chai testing. But getting this error when mock API is being called. Couldn't find any relatable and helpful answers on google yet. Any help will be much appreciated. I have been stuck on this for 2 full days!
'ExpectationError: Unexpected call: get('https://BASE_URL/api/invoiceDetails.php', {\n params: { dealerGCD: 'XXXXXX', monthUploaded: '5', yearUploaded: '2022' }\n})\n Expected get('https://BASE_URL/api/invoiceDetails.php', {\n params: { dealerGCD: 'XXXXXX', monthUploaded: 5, yearUploaded: 2022 }\n}) once (never called)\n Expected get('https://BASE_URL/api/invoiceDetails.php', {\n params: { dealerGCD: 'XXXXXX', monthUploaded: '2', yearUploaded: '2022' }\n}) once …icDataService.getInvoiceDetail (/media/disk1/IFM/Micro Services/REPO_NAME/src/core/services/BasicDataService.ts:53:16)\n at BasicDataFlow.<anonymous> (/media/disk1/IFM/Micro Services/REPO_NAME/src/core/flows/BasicDataFlow.ts:54:60)\n at Generator.next (<anonymous>)\n at fulfilled (/media/disk1/IFM/Micro Services/REPO_NAME/src/core/flows/BasicDataFlow.ts:5:58)\n at processTicksAndRejections (node:internal/process/task_queues:96:5)'

Related

How to a pass a complex object as a mock data service stub

I'm working on a test for a module, which works except for the fact that I can not access, the inner object attributes properties.
tokenStorageServiceStub = { // Mock service data
getUser: () => of({
username: 'organization-a-a-normal',
roles: ['PROCESSOR'],
attributes: {
organizationId: 111,
organizationName: 'Org.name Aa',
userFullName: 'User for organization A-A',
userId: 22,
},
access_token: 'AT01',
refresh_token: 'RT01',
token_type: 'Bearer',
expires_in: 3600,
}),
};
The component code complains about the last statement:
this.activeTokens = this.token.getUser(); // OK
this.username = this.activeTokens.username; // OK
this.organization.id = this.activeTokens.attributes.organizationId; // `attributes` is undefined?
Chrome Headless 88.0.4298.0 (Linux x86_64) SettingsComponent should create FAILED
TypeError: Cannot read property 'organizationId' of undefined
at SettingsComponent.call [as ngOnInit] (src/app/organization/settings/settings.component.ts:22:61)
I think it's because of the innerworking of the RxJs.of() function. In the manual, I see things like ObservableInput. But there is no mention of Objects as such.
I also read about of() getting deprecated? What will be a good approach to pass my object data in a test service stub?

adonis test returning message: "superagent: Enable experimental feature http2"

My testing is passing normally, but i’m receiving the message: “superagent: Enable experimental feature http2”
There’s a way to hide this message?
My test:
test('realiza um registro de usuário', async ({ client }) => {
const response = await client
.post('users')
.header('Authorization', 'bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1aWQiOjMsImlhdCI6MTU3MjQ0MTA2M30.qN4OMAznOj4blEECSUs-miIMn8DLiAvonrYKxysH7y0')
.send({
username: 'usuarioteste',
permission: 'Administrador',
status: false,
user_id: null,
password: 'usuarioteste'
})
.end()
response.assertStatus(200)
response.assertJSONSubset({
username: 'usuarioteste',
permission: 'Administrador',
status: false
})
})
When i run adonis test i receive:
superagent: Enable experimental feature http2
✓ realiza um registro de usuário (447ms)
PASSED
There's a way to hide this superagent: Enable experimental feature http2 warning? Someone can explain me what this is happen?
This is not an error message, it's only an information message. This does not matter how the tests are conducted.
The message appears during the functional tests.This must be a dependency used by #adonisjs/vow.
To my knowledge, I don't think it's possible to hide it.

IBM IAM API KEY AUTHENTICATION ERROR

I am executing the code below.. I have supplied the correct API but keep getting an authentication error (provided below)
Here's the code snippet
// Example 1: sets up service wrapper, sends initial message, and
// receives response.
const AssistantV2 = require('ibm-watson/assistant/v2');
// Set up Assistant service wrapper.
const service = new AssistantV2({
iam_apikey: 'xxx', // replace with API key
version: '2019-02-28',
});
const assistantId = 'xxx'; // replace with assistant ID
let sessionId;
Here's the error message
C:\Users\User\Desktop\Insurancebot\test>node sample.js
{ Unauthorized: Access is denied due to invalid credentials.
at RequestWrapper.formatError (C:\Users\User\node_modules\ibm-cloud-sdk-core\lib\requestwrapper.js:219:21)
at C:\Users\User\node_modules\ibm-cloud-sdk-core\lib\requestwrapper.js:207:29
at process._tickCallback (internal/process/next_tick.js:68:7)
name: 'Unauthorized',
code: 401,
message: 'Access is denied due to invalid credentials.',
body: '{"code":401,"error":"Unauthorized"}',
headers:
{ 'x-backside-transport': 'FAIL FAIL',
'content-type': 'application/json',
'x-dp-transit-id': 'gateway02-3627341245',
'x-global-transaction-id': 'ffea405d5d0083b9d834d5bd',
'strict-transport-security': 'max-age=31536000;',
'x-dp-watson-tran-id': 'gateway02-3627341245',
'content-length': '37',
'x-edgeconnect-midmile-rtt': '110',
'x-edgeconnect-origin-mex-latency': '132',
date: 'Wed, 12 Jun 2019 04:46:49 GMT',
connection: 'close' } }
Outside of the wrong IAM key, the most common cause is the wrong service endpoint being used.
It defaults to US, so if you have set up your assistant in U.K. for example, you would set: url: ‘https://gateway-lon.watsonplatform.net/assistant/api’
The full list is here:
https://cloud.ibm.com/apidocs/assistant#service-endpoint

Fetch with react native

I am using fetch in React Native in order to make a call to my API, however, it only works 75% of the time.
When my request doesn't work I get this :
TypeError: Network request failed
or
SyntaxError: Unexpected token < in JSON at position 0
fetch('http://localhost/vision.php', {
method: 'POST',
headers: {
'Accept': 'application.json',
'Content-Type': 'application.json',
},
body: JSON.stringify({
key: 'Mon paramètre'
})
})
.then((data) => data.json())
.then((dataJson) => {
console.log(dataJson.message);
})
.catch((error) => {
console.log(error);
});
}
Someone can explain that ?
When you get TypeError: Network request failed, it means that, well, the network request failed. It could mean the API / server you're trying to connect to is down / not listening for connections anymore.
Regarding SyntaxError: Unexpected token < in JSON at position 0, that's what you get when trying to parse non-JSON as JSON. Typically here it's likely your API / server failing to fulfill your request and, instead of JSON, serving you an HTML error page.
You might want to check if data.ok is true before trying to parse the JSON response (data.json()).

Cannot Checkin Through FB.api (javascript)

With the javascript sdk (FB.api), I cannot checkin on behalf of user.
(The user has granted publish_stream permission to my app)
Since facebook's API keeps changing, confused for some time. After searching and reading from internet, I think it's the right way to publish a checkin. Any help is appreciated.
var params = {
method: 'POST',
place: 107297282684980,
message: 'hi',
coordinates: {
'latitude': 22.204284439454,
'longitude': 113.54313260065
}};
FB.api(
'/me/checkins',
params,
function(response) {
if( response )
alert('Checkin Completed!');
});
It was deprecated at July 2013. You should check the changes from the URLs provided at the question comment.
And follow the instructions:
https://developers.facebook.com/docs/opengraph/overview/
https://developers.facebook.com/docs/opengraph/getting-started/
As FB Check-In is deprecated we can achieve the same thing with a post on FB with Location Attached using the following FB Graph Api post.
FB.api('/me/feed', 'post', {
name: 'SomeName',
message: 'SomeMessage',
place: yourLocationID
}, function (response) {});
Note : Where yourLocationID is the ID that you will get by the Graph search using https://graph.facebook.com/search?q=yourPlaceName&type=page&access_token=YOURTOKEN