how to test with custom dom event in angularjs - unit-testing

I have written custom events for mobile devices in jasmine,
and I am trying to fire the events.
so instead of
angular.element()[0].click()
how may I trigger custom events and other events to trigger functions?

This should work:
angular.element().triggerHandler('my-custom-event-name');
If you want to attach additional data to your event:
angular.element().triggerHandler('my-custom-event-name', {'foo': 'bar'});

To add to the above post, you can pass a custom event (with extra data) by doing this:
angular.element().triggerHandler({
'type': 'my-custom-event-name',
'foo': 'bar'
});

Related

Accessing an event's atttributes in AWS Pinpoint Campaign email template

I have an AWS Pinpoint application.
On the web app front-end, I can trigger an event as follows:
await record('my.event', {
attributes: { color: 'red', size: 'large' },
immediate: true
})
In Pinpoint, I can create a campaign with an email template to send an email to the user whenever my.event is triggered. I'm able to access the endpoint attributes such as {{User.UserAttributes.GivenName}} or {{Attributes.Preferences.Hats}}.
However, I'm not able to access the event attributes (color, size) in the above example in the email template.
Is there a way to do this?
It seems like you can only filter the events to determine whether the campaign email should be sent (e.g., send only if color==='blue').
I suppose that I could temporarily update the endpoint Attributes before triggering the event, but that is not preferred as it requires an additional call.
I'm not entirely sure, but I think accepted attribute values must be lists, such as color: ["red"]

Can a lambda that uses vendia serverless-express be a step in a state machine?

I have a lambda setup that uses vendia serveless-express as a handler. It has been working well to serve REST APIs from the single lambda function with multiple routes.
I now have a new requirement, where the same lambda needs to be part of a step function's state machine. But that doesn't seem to be allowed by vendia app, as it always throws the error: "Unable to determine event source based on event" as it expects the event to be api gateway / alb only.
So, based on this, it looks like I will need a separate lambda for step, which makes me have duplicate code in multiple lambdas.
Is it possible for the lambda to handle the inputs from step and still be a vendia express app? Please let me know if I am trying something that doesn't make sense at all.
If I were you I would just implement my own converter that transforms a StepFunction event into an API Gateway event and then calling the express-serverless in your lambda.
The package aws-lambda contains definitions in TypeScript of many AWS events including those ones, then try to generate a mock API Gateway event from your own step function event value. From the sources (4.3.9) we have the function:
function getEventSourceNameBasedOnEvent ({
event
}) {
if (event.requestContext && event.requestContext.elb) return 'AWS_ALB'
if (event.Records) return 'AWS_LAMBDA_EDGE'
if (event.requestContext) {
return event.version === '2.0' ? 'AWS_API_GATEWAY_V2' : 'AWS_API_GATEWAY_V1'
}
throw new Error('Unable to determine event source based on event.')
}
So probably to make it work correctly, you have to define a RequestContext mock value in your mock event and it should be enough.

AWS SNS - how should I be sending message data, MessageAttributes?

I'm building an application that enables clients to book appointments with service providers. I'm using SNS -> SQS -> Lambda to process various emails that need to be sent when booking an appointment. IE I currently send an SNS message like so (in node.js):
await sns.publish({
Message: 'booking-request',
TopicArn: process.env.AWS_BOOKING_REQUEST_TOPIC_ARN,
MessageAttributes: {
artistEmail: SNSMF.string(artist.email),
artistName: SNSMF.string(artist.name),
clientEmail: SNSMF.string(req.body.email),
clientName: SNSMF.string(`${req.body.firstName} ${req.body.lastName}`),
date: SNSMF.string(moment(req.body.date).tz(studio.timeZone).format())
}
}).promise();
This all works fine, but I'm using MessageAttributes to pass the pertinent appointment details so my notifications layer can send the proper emails.
My main questions is, am I using MessageAttributes in the proper way, or is there a better way to pass all of this data? Should the data be the message itself? I ask because I believe that you can only have 10 MessageAttributes and I'm going to run into a limit with the appointment details (currently collecting about 10-12 data points about the appointment that I want to include in the emails). Any ideas? Thank you!
Normally, the 'main' information you wish to pass would be in the Body of the message. It is quite common the use JSON to pass various types of information.
MessageAttributes are normally something about the message itself rather than the content of the message, such as timestamps, priority and user information.
Given your requirements, I putting your data in the Body (eg in JSON) would avoid hitting limits and would also be more extensible.

Fire action in Backbone View after two events have been triggered

I understand how to bind an action in a Backbone View to an event trigger but, how can you fire an action watching the condition that two precise envets have been triggered?
For that you can use jquery functionality like:
$.when(func1, func2).then(func3);
It acts like deffered and promise here.

Is it possible to get access to the HTTP Context from within a Sitecore Event handler?

I am building a custom event handler for the Sitecore security:loggedin event. Basically I want to run some code every time a user logs in. Is it possible for me to get access to the HttpContext (application level variables, etc) from within the event handler code? From what I can tell the only argument that is passed in is the User object for the user that just logged in.
Thanks,
Corey
Yes, this is entirely possible:
if (System.Web.HttpContext.Current != null)
{
//do what you like
}