Fix migration of old pending SMS sends.

master
Greyson Parrelli 2019-10-03 16:07:53 -04:00
parent 0f06b96832
commit 0fa48540e1
2 changed files with 23 additions and 3 deletions

View File

@ -193,8 +193,12 @@ public class RecipientIdJobMigration extends JobMigration {
private @NonNull JobData migrateSmsSendJob(@NonNull JobData jobData) {
//noinspection ConstantConditions
Recipient recipient = Recipient.external(application, jobData.getQueueKey());
return jobData.withQueueKey(recipient.getId().toQueueKey());
if (jobData.getQueueKey() != null) {
Recipient recipient = Recipient.external(application, jobData.getQueueKey());
return jobData.withQueueKey(recipient.getId().toQueueKey());
} else {
return jobData;
}
}
@VisibleForTesting

View File

@ -333,7 +333,7 @@ public class RecipientIdJobMigrationTest {
}
@Test
public void migrate_smsSendJob() throws Exception {
public void migrate_smsSendJob_nonNull() throws Exception {
JobData testData = new JobData("SmsSendJob", "+16101234567", new Data.Builder().putLong("message_id", 1).putInt("run_attempt", 0).build());
mockRecipientResolve("+16101234567", 1);
@ -348,6 +348,22 @@ public class RecipientIdJobMigrationTest {
new SmsSendJob.Factory().create(mock(Job.Parameters.class), converted.getData());
}
@Test
public void migrate_smsSendJob_null() throws Exception {
JobData testData = new JobData("SmsSendJob", null, new Data.Builder().putLong("message_id", 1).putInt("run_attempt", 0).build());
mockRecipientResolve("+16101234567", 1);
RecipientIdJobMigration subject = new RecipientIdJobMigration(mock(Application.class));
JobData converted = subject.migrate(testData);
assertEquals("SmsSendJob", converted.getFactoryKey());
assertNull(converted.getQueueKey());
assertEquals(1, converted.getData().getLong("message_id"));
assertEquals(0, converted.getData().getInt("run_attempt"));
new SmsSendJob.Factory().create(mock(Job.Parameters.class), converted.getData());
}
private void mockRecipientResolve(String address, long recipientId) throws Exception {
doReturn(mockRecipient(recipientId)).when(Recipient.class, "external", any(Context.class), eq(address));
}