I have a setInterval()
that's a countdown on the screen. I have a method that should be triggered when the clock reaches -5 minutes.
That part is covered, the method is being called however, it's not running. The reason I say it's being called but it doesn't run is because I have a console.log
on the first line of the method to tell me that it was called but nothing happens. It dies there.
The method, for now, will create an object and console.log for me.
here it is:
set interval
return this.timeRef = setInterval(() => {
this.counter = startTime - Date.now();
this.hours = Math.floor((this.counter / (1000 * 60 * 60)) % 24);
this.minutes = Math.floor( (this.counter / 60000) % 60 );
this.seconds = Math.floor(Math.floor(this.counter % 60000) / 1000);
// Hours
if (Math.sign(this.hours) !== -1) {
if (this.hours < 10) {
this.hours = '0' + this.hours;
}
} else {
this.hours = '-0' + ( -this.hours - 1);
}
// Minutes
if (Math.sign(this.minutes) !== -1) {
if (this.minutes < 10) {
this.minutes = '0' + this.minutes;
}
} else {
// If it's 5 minutes after the end of the shift.
// tslint:disable-next-line: radix
if (parseInt(this.hours) <= 0 && -this.minutes === 16) {
if (smsSent === false) {
this.sendRdSMS(); // HERE IS WHERE THE METHOD GETS CALLED.
}
smsSent = true;
}
if (-this.minutes < 10) {
this.minutes = '0' + -this.minutes;
} else {
this.minutes = -this.minutes;
}
}
// Seconds
if (Math.sign(this.seconds) !== -1) {
if (this.seconds < 10) {
this.seconds = '0' + this.seconds;
}
} else {
if (-this.seconds === 60) {
this.seconds = '00';
} else if (-this.seconds < 10) {
this.seconds = '0' + -this.seconds;
} else {
this.seconds = -this.seconds;
}
}
// Send Local Push Notification
if (this.hours === '00' && this.minutes === '05') {
if (alertSent === false) {
const localMessage = `Hey ${this.user$.firstName}! \
This is a reminder that your time is almost up. \
We hope you had an amazing a productive day.;
this.alertTrigger(localMessage);
}
alertSent = true;
}
}, 1000);
Here is the method that's supposed to run
sendRdSMS() {
console.log('called sendSMS');
this.userUservice.getRD(this.user$.rd)
.then(
(rdData: User) => {
const smsObj = {
rdPhone: rdData.cellphone,
rdName: `${rdData.firstName}`,
userName: `${this.user$.firstName} ${this.user$.lastName}`,
isEmergency: false
};
console.log(smsObj);
const callable = this.cloudFunctions.httpsCallable('sendSMS');
callable(smsObj)
.then(
response => {
console.log('ok');
}
)
.catch(
(err) => console.log(err)
)
.finally(
() => console.log('it ran')
);
}
)
.catch(
(err) => console.log(err)
)
.finally(
() => console.log('it ran')
);
}