Mocking JSforce with Jest

by Patrick Connelly posted on March 30, 2021

Testing is one of the most important things you can do your code. However, when using a library that requires access to a remote system unit testing can become problematic. You don’t want to have to have a real connection and pull down real data since this is slow and requires anyone contributing to your project to set up the remote system as well. This is where mocking comes in with Jest.

Mocking allows you to detach a module from making a remote call and allows you to define the data that it returns. This means that you can modify the data how you need to provide a small data set or a large data set or even error out on demand.

In this post, we’re going to look at how to set up mocking for JSforce to test logging in and mocking out making queries.


Tracking water softener, water and air filters in Home Assistant

by Patrick Connelly posted on November 06, 2020

One of the things I’m terrible about remembering is changing air filters and I leave them in for way to long. And with our recent move into the new house not only do I have more air filters and a fridge water filter but now I have a whole house water filter, water softener and UV filter to keep track of. I’ve been spending a bunch of time working on my Home Assistant and I decided that since I use this system multiple times a day, I might as well track these filter’s life span on the same platform


OBS and Zoom - Live streaming to Zoom with multiple cameras

by Patrick Connelly posted on May 18, 2020

One of the hardest things about doing instructional content virtually is when you have to show things that are not on a screen. This came to be an issue for my father when he needed to teach the art merit badge for the Boy Scouts this summer. While lots of the work for the merit badge can be done via a presentation, there is still quite a lot that either has to be done in “meat space” or benefits greatly from being done in a tangible way. The scout camp he is working with this summer is doing all of their merit badge classes over Zoom and with the power of the open source application OBS we were able to give him a more professional setup without spending thousands of dollars or hiring a full-time video crew.


JWT Bearer Authentication: Salesforce and Node

by Patrick Connelly posted on March 08, 2019

If you’ve done much API generation then you’ll that you don’t want to have to make your users authenticate multiple times just because your API is going somewhere external. For example, if you have an API that reaches into Salesforce but your app uses Google SSO, you don’t want to have to present an oauth screen to your user after they’ve already authenticated. To work around this, you can use a JWT Bearer flow to login on behalf of a user and get a access token to work with.


Single Sign-On in Salesforce with Google

by Patrick Connelly posted on March 05, 2019

I started down this path to flesh out a proof of concept for a related task. However, the Single Sign-On provider that we use is difficult to get access to and not worth the time to try to get permission to use it. So instead, I thought I’d just use my personal Google domain as the identity provider so I can get it done faster. So I’ve decided to document my journey and hopefully help someone else set this up.


Pi-hole setup on Raspberry Pi Zero

by Patrick Connelly posted on February 11, 2019

If you’ve not noticed, ads on the internet are everywhere. On my personal machine, I run uMatrix in chrome and it works great for blocking things but that’s not really an option for all devices (like mobile phones) or for all users (like my wife and kids). This is where Pi-hole comes in.

Pi-hole is an application that runs a customized DNS (Domain Name System) server that whenever a system using it tries to look up the name of and if it’s on the Pi-hole’s blacklist it pretends that the host doesn’t exist. Thus your device can’t see the ad server and then can’t load the ad.


Change Data Capture with Nodejs

by Patrick Connelly posted on January 23, 2019

There’s a new feature in Salesforce called Change Data Capture that allows you to subscribe to a Cometd endpoint and stream changes to most or some of your objects. I’ve talked in a previous post about how to get data out of Salesforce and this seems like it might be the front-runner for one of the best ways. I would still plan on ways to get data if it exceeds the three day replay period and you’ll also need a way to do your initial data import.

What data can I get with Change Data Capture?

In a perfect world, everything you’d need would always live in Salesforce and you’d never have to worry about backing up data. Well, we don’t live in a perfect world. Lot’s of times you need to get data out of Salesforce and get it into an external system. You could do this for data backup, for populating a search index, for sending messages to an external system. With Change Data Capture, you can do this type of data flow in real-time.

Change Data Capture supports the following standard object (at time of writing):

  • Account
  • AccountContactRole
  • Asset
  • Campaign
  • Case
  • Contact
  • Event
  • EventRelation
  • Lead
  • ListEmail
  • Opportunity
  • OpportunityContactRole
  • Order
  • OrderItem
  • Product2
  • Task
  • User

In addition to the standard items above, Change Data Capture supports all custom objects.


Away time in Home Assistant and surviving reboots

by Patrick Connelly posted on November 28, 2018

One of the biggest reasons I wanted to set up Home Assistant was to be able to handle a “vacation mode” for my house to change things like the thermostats and lighting. The addition of an input_boolean for this is really straight forward. However reminding myself to set vacation mode if we are away for a long period of time is something a bit harder. To do this, we need to calculate the away time for each user.

The Problem

The linchpin for knowing if I should send a reminder is around how long a person has been away. Originally thought I could just use my Ubiquiti access point’s last_seen time and calculate hours from there. However this field disappears after about 10 minutes of the user being disconnected from the access point. So I needed to find a way to persist the last_seen time event after the access point removes the data from the device_tracker entry.


PMD and Salesforce: Clean Code is Awesome

by Patrick Connelly posted on July 06, 2018

If you’re not aware, having clean code is more than just about readability. It’s about sustainability, re-usability and knowing that your code is doing what you want it to do. This is where PMD comes into the picture. PMD is a static code analysis tool that takes code from many different languages, analyzes it and provides you with feedback. Fortunately for the Salesforce world PMD now supports Apex as one of it’s languages. So, let’s dive into how to set it up, run it and then how to use some of the rules included.


Turning off a warmer: An intro to home automation

by Patrick Connelly posted on March 11, 2018

Scooter

Now this little warmer may look innocent enough, but it’s a disaster waiting to happen. If you leave it alone, it will kill your whole family without remorse. Ok, that may be a bit hyperbolic, but these things can be kind of dangerous. According to the National Fire Protection Association in 2013 seven people died each day in the US due to home fires. And half of those deaths occurred between the hours of 11 pm and 7 am. Now, how many were caused by this cute little scooter, probably not many. But devices like this can cause fires. This scooter is a wax warmer. It heats up a tray that melts wax and makes your house smell lovely. But if you leave it on too long (by lets say forgetting about it and leaving it on for 48 hours) you get a different result. This has happened more than once in our household, and that’s what leads me to my first real world application of home automation.