Fix migration of old pending SMS sends.
parent
0f06b96832
commit
0fa48540e1
|
@ -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
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue