13" MacBook Pro 2017 randomly shutting down
Reset the SMC

I would start by resetting the SMC on your MBP. Follow these steps:


Shut down your MBP
Press and hold the power button for at least 10 seconds
Let go of the power button and wait 5 seconds
Power up your MBP again


Once you've reset the SMC use your MBP as usual. If you still feel it's shutting down too soon or perhaps not charging as it normally would, then reset the SMC again but with the following steps instead:


Shut down your MBP
Press and hold the right shift key and the left option and control keys for 7 seconds before then also pressing and holding the power button down for another 7 seconds (i.e. the keys will end up being held down for 14 seconds, the power button for 7 seconds)
Let go of all three keys and the power button
Wait 5 seconds
Power up your MBP again


Also, macOS provides a great deal of information about your power usage. Read on to see how to access this.

Checking your charging status within macOS

Follow these steps:


Go to Apple > About This Mac
Click on the System Report... button
In the left pane under the Hardware heading, select Power (it's about 2/3 of the way down)
On the right-hand side, scroll down to view the AC Charger Information
This will show you whether it's connected to a charger, the amount of wattage it's receiving, and if it's currently charging or not