Question
I set up the following Jest test to ensure an exception is thrown:
it('can not rollback a step', async () => {
await expect(app.service('rides').patch(ride._id, {
currentStep: 1,
})).rejects.toThrow(BadRequest);
});
How can I assert the exception content?
Example
Considering this BadRequest error:
BadRequest {
type: 'FeathersError',
name: 'BadRequest',
message: 'invalid data',
code: 400,
className: 'bad-request',
data: {},
errors: [
{
message: 'currentStep must be greater than 1',
path: [Array],
type: 'array.min',
context: [Object]
}
],
I would like to check errors[0].message content, regardless the rest of the error object.
you catch and then analyze. Don't forget jest.assertions() to ensure code really throws.
jest.assertions(1);
try {
await app.service('rides').patch(ride._id, {
currentStep: 1,
});
} catch(e) {
expect(e.errors[0].message).toEqual('abc');
}
Related
I'm trying to use dynamoDb with API Gateway, but it is not working. This is what I'm trying to do
export async function handler(event: APIGatewayProxyEvent, context: Context): Promise<APIGatewayProxyResult> {
switch (event.httpMethod) {
case "GET":
var params = {
TableName: 'Users',
Key: {
UserID: event.queryStringParameters.UserID
}
};
dynamodb.get(params, function (err, data) {
if (err){
return{
statusCode: 200,
body: JSON.stringify({
message: "Item not found"
})
}
} else {
return {
statusCode: 200,
body: JSON.stringify({
message: data.Item,
})
};
}
})
break;
}
Every time I try to call my gateway I get a
{
"message": "Internal server error"
}
Is it a problem with my integration ?
Another doubt, how can I add other routes to my Gateway ? I'm using CloudFloration Template and it's this:
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Resources:
UserAPI:
Type: AWS::Serverless::Function
Properties:
Handler: build/userAPI.handler
Runtime: nodejs14.x
Events:
Api:
Type: Api
Properties:
Path: /users
Method: ANY
How can I add a route like /user (GET) or /users (POST) ?
As requested I get the logs so the lambda is no been invoked the error I get is:
2021-06-23T12:08:37.557Z eb945ca9-a4b6-4f8e-add1-774276db2cb7 ERROR Invoke Error {
"errorType": "TypeError",
"errorMessage": "Cannot read property 'UserID' of null",
"stack": [
"TypeError: Cannot read property 'UserID' of null",
" at Runtime.handler (/var/task/build/userAPI.js:12:57)",
" at Runtime.handleOnce (/var/runtime/Runtime.js:66:25)"
]
}
I'm using namespaced modules for state management in vuex, I try to keep all my actions mutations inside my modules as this helps me keep most of my code in the same place (modules acting like classes or similar) hoever there's an issue, I'd like to fire a component method to clear a form when a vuex action is successfull (that is the axios request gets an OK/200 response) but sadly I can't fire a methos from vuex module into my component ( there's no this inisde module).
I also tried adding a .then to my action call but it fires right after I call the action...
I guess I could move the action into the component itself but I'd rather not, what do you guys suggest?
My component:
stripeSourceHandler: function(sourceId)
{
if(this.customerSources.length == 0)
{
console.log('createSourceAndCustomer');
this.createSourceAndCustomer({ id: sourceId });
}
else
{
console.log('addSource');
this.addSource({ id: sourceId }).then(alert('Form cleared')); //this fires right after calling addSource
};
},
My module action:
addSource({ commit }, sourceId)
{
commit('Loader/SET_LOADER', { status:1, message: 'Procesando...' }, { root: true });
axios.post('/stripe/add-source', sourceId)
.then((response) => {
commit('Loader/SET_LOADER', { status:2, message: response.data.message }, { root: true });
commit('ADD_SOURCE', response.data.customer);
//I can't clear component form from this...
},
(error) => {
commit('Loader/SET_LOADER', { status:3, errors: error, message: 'Error al añadir el pago.' }, { root: true });
});
},
Two issues:
You need to return the promise from the action so that you can use .then() to schedule code to be executed once the action has completed (this code being whatever you need to do to clear the form).
.then() takes one (or two) functions as parameters which will be called once the promise has resolved, instead you're just calling alert() immediately.
It'll be something like:
Component method
stripeSourceHandler(sourceId) {
if (this.customerSources.length == 0) {
this.createSourceAndCustomer({ id: sourceId });
} else {
this.addSource({ id: sourceId }).then(() => {
// Clear the form here
alert('Form cleared');
});
}
}
Vuex action
addSource({ commit }, sourceId) {
commit('Loader/SET_LOADER', { status:1, message: 'Procesando...' }, { root: true });
// Return the promise here
return axios.post('/stripe/add-source', sourceId)
.then(response => {
commit('Loader/SET_LOADER', { status:2, message: response.data.message }, { root: true });
commit('ADD_SOURCE', response.data.customer);
}, error => {
commit('Loader/SET_LOADER', { status:3, errors: error, message: 'Error al añadir el pago.' }, { root: true });
});
}
i want to gatsby stripe serverless checkout , i added products on stripe. but i cant install gatsby-source-stripe or gatsby-source-stripe-products. error;
error UNHANDLED EXCEPTION
Error: /...../node_modules/gatsby-source-stripe/gatsby-node.js:4
exports.sourceNodes = async ({ actions }, { objects = [], secretKey = "" }) => {
^^^^^^^^^^^^
SyntaxError: Invalid shorthand property initializer
gatsby-config
{
resolve: `gatsby-source-stripe`,
options: {
objects: [
'balance',
'customers',
'products',
'applicationFees',
'skus',
'subscriptions'
],
secretKey: process.env.STRIPE_SECRET
}
},
i have .env file.
Make sure you have entered test SKUs in Stripe - you can do so by toggling the View test data.
Given the following parent-process code:
//SSO
this.sso = fork('./app/utils/SSOproxy.js', [], {
stdio: [0, 1, 2, 'ipc']
});
console.log(process);
console.log(this.sso);
//__handshake
this.sso.send({
opcode: 'ACK',
params: [],
ref: null
});
console.log('STEP_1');
process.prependOnceListener('message', ((msg) => {
if (msg.status) {
if ((msg.opcode === 'ACK') && (msg.params[0] === 'ok')) {
console.log('STEP_3');
}
}
}));
//__e.o.handshake
And child-process (SSOproxy.js) code:
process.on('message', ((msg) => {
switch (msg.opcode) {
//handshake
case 'ACK':
process.send({
opcode: 'ACK',
params: ['ok'],
ref: null
});
console.log('STEP_2');
break;
//Other paths...
}
));
In the log observed - STEP_1 is followed by STEP_2 but I never see STEP_3 because I can't for-the-life of me figure out how to get duplex communication for child/parent. How to achieve the same?
In your prependOnceListener you have a condition for msg.status but I don't see this anywhere in your SSOproxy.js code.
This means your if will never evaluate true
Can you try adding a status to your message:
process.send({
opcode:'ACK',
params:['ok'],
ref: null,
status: 'test1234'
});
Using the service-configuration and accounts-facebook packages, after clicking on the facebook button and logging in from the Facebook authorization window that pops up, we're getting an Internal server error when performing a Meteor.loginWithFacebook.
This was tested on a very basic example, what is causing this error?
Template.login.events({
'click .btn-facebook': function (ev) {
Meteor.loginWithFacebook({}, function(error) {
if(error) {
throw new Meteor.Error('Facebook login failed: ', error);
}
})
}
});
/server/lib/config/social.js
Meteor.startup(function() {
ServiceConfiguration.configurations.update(
{ service: "facebook" },
{ $set: {
appId: "xxx",
secret: "xxx"
}
},
{ upsert: true }
);
})
Error (server side)
Exception while invoking method 'login' undefined
Error (client side)
Error: Internal server error [500]
at _.extend._livedata_result (http://localhost:3000/packages/ddp.js?d1840d3ba04c65ffade261f362e26699b7509706:4964:23)
at onMessage (http://localhost:3000/packages/ddp.js?d1840d3ba04c65ffade261f362e26699b7509706:3725:12)
at http://localhost:3000/packages/ddp.js?d1840d3ba04c65ffade261f362e26699b7509706:2717:11
at Array.forEach (native)
at Function._.each._.forEach (http://localhost:3000/packages/underscore.js?0a80a8623e1b40b5df5a05582f288ddd586eaa18:156:11)
at _.extend._launchConnection.self.socket.onmessage (http://localhost:3000/packages/ddp.js?d1840d3ba04c65ffade261f362e26699b7509706:2716:11)
at REventTarget.dispatchEvent (http://localhost:3000/packages/ddp.js?d1840d3ba04c65ffade261f362e26699b7509706:156:22)
at SockJS._dispatchMessage (http://localhost:3000/packages/ddp.js?d1840d3ba04c65ffade261f362e26699b7509706:1141:10)
at SockJS._didMessage (http://localhost:3000/packages/ddp.js?d1840d3ba04c65ffade261f362e26699b7509706:1199:18)
at WebSocket.SockJS.websocket.that.ws.onmessage (http://localhost:3000/packages/ddp.js?d1840d3ba04c65ffade261f362e26699b7509706:1346:17)
I had the same issue, and solved it like this :
After checking that you have configured your schema as described here :
Schema.User = new SimpleSchema({
_id: {
type: String
}
...
});
You should add the second part into an Accounts.onCreateUser like this, into server/accounts.js for example :
Accounts.onCreateUser(function (options, user) {
if (user.services.facebook) {
user.emails = [{
address: user.services.facebook.email,
verified: true
}];
}
return user;
});
It will append the facebook email to the newly created account. The error should disapear.