Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 353cb15

Browse files
author
jjbennett
committed
Fixes from code review and cleanup of unused methods.
1 parent 9f0e7d3 commit 353cb15

File tree

5 files changed

+144
-37
lines changed

5 files changed

+144
-37
lines changed

force-app/main/default/classes/ServiceDeliveryController_TEST.cls

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,86 @@ public with sharing class ServiceDeliveryController_TEST {
249249
);
250250
}
251251

252+
@IsTest
253+
private static void testUpsertServiceDeliveries() {
254+
List<ServiceDelivery__c> serviceDeliveries = new List<ServiceDelivery__c>{
255+
new ServiceDelivery__c(
256+
Name = 'Test1',
257+
Id = TestUtil.mockId(ServiceDelivery__c.SObjectType)
258+
),
259+
new ServiceDelivery__c(
260+
Name = 'Test2',
261+
Id = TestUtil.mockId(ServiceDelivery__c.SObjectType)
262+
),
263+
new ServiceDelivery__c(
264+
Name = 'Test3',
265+
Id = TestUtil.mockId(ServiceDelivery__c.SObjectType)
266+
)
267+
};
268+
269+
domainStub.withReturnValue(
270+
'upsertServiceDeliveries',
271+
new List<Type>{ List<Database.UpsertResult>.class, Boolean.class },
272+
null
273+
);
274+
275+
Test.startTest();
276+
ServiceDeliveryController.deliveryDomain = (ServiceDeliveryDomain) domainStub.createMock();
277+
ServiceDeliveryController.upsertServiceDeliveries(serviceDeliveries, false);
278+
Test.stopTest();
279+
280+
domainStub.assertCalledWith(
281+
'upsertServiceDeliveries',
282+
new List<Type>{ List<ServiceDelivery__c>.class, Boolean.class },
283+
new List<Object>{ serviceDeliveries, false }
284+
);
285+
}
286+
287+
@IsTest
288+
private static void testUpsertServiceDeliveriesException() {
289+
List<ServiceDelivery__c> serviceDeliveries = new List<ServiceDelivery__c>{
290+
new ServiceDelivery__c(
291+
Name = 'Test1',
292+
Id = TestUtil.mockId(ServiceDelivery__c.SObjectType)
293+
),
294+
new ServiceDelivery__c(
295+
Name = 'Test2',
296+
Id = TestUtil.mockId(ServiceDelivery__c.SObjectType)
297+
),
298+
new ServiceDelivery__c(
299+
Name = 'Test3',
300+
Id = TestUtil.mockId(ServiceDelivery__c.SObjectType)
301+
)
302+
};
303+
304+
domainStub.withThrowException(
305+
'upsertServiceDeliveries',
306+
new List<Type>{ List<ServiceDelivery__c>.class, Boolean.class }
307+
);
308+
309+
Test.startTest();
310+
ServiceDeliveryController.deliveryDomain = (ServiceDeliveryDomain) domainStub.createMock();
311+
312+
Exception actualException;
313+
try {
314+
ServiceDeliveryController.upsertServiceDeliveries(serviceDeliveries, false);
315+
} catch (Exception e) {
316+
actualException = e;
317+
}
318+
Test.stopTest();
319+
320+
System.assertEquals(
321+
domainStub.testExceptionMessage,
322+
actualException.getMessage(),
323+
'Expected the controller to rethrow the exception from the domain.'
324+
);
325+
domainStub.assertCalledWith(
326+
'upsertServiceDeliveries',
327+
new List<Type>{ List<ServiceDelivery__c>.class, Boolean.class },
328+
new List<Object>{ serviceDeliveries, false }
329+
);
330+
}
331+
252332
@IsTest
253333
private static void testGetNumberOfServiceDeliveriesForSession() {
254334
Integer expectedNumberOfDeliveries = 5;

force-app/main/default/classes/ServiceDeliveryDomain_TEST.cls

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,59 @@ private with sharing class ServiceDeliveryDomain_TEST {
159159
}
160160
}
161161

162+
@IsTest
163+
private static void shouldReturnUpsertResultsOnUpsertServiceDeliveriesWithAllOrNone() {
164+
TestDataFactory.generateServiceData();
165+
Service__c service = [SELECT Id FROM Service__c LIMIT 1];
166+
167+
List<ServiceDelivery__c> existingServiceDeliveries = [
168+
SELECT Id, Name
169+
FROM ServiceDelivery__c
170+
];
171+
for (ServiceDelivery__c delivery : existingServiceDeliveries) {
172+
System.assertNotEquals('Upserted', delivery.Name);
173+
delivery.Name = 'Upserted';
174+
delivery.AutonameOverride__c = true;
175+
}
176+
177+
ServiceDelivery__c newServiceDelivery = new ServiceDelivery__c(
178+
Name = 'Upserted',
179+
AutonameOverride__c = true,
180+
Service__c = service.Id
181+
);
182+
183+
List<ServiceDelivery__c> serviceDeliveriesToUpsert = new List<ServiceDelivery__c>();
184+
serviceDeliveriesToUpsert.addAll(existingServiceDeliveries);
185+
serviceDeliveriesToUpsert.add(newServiceDelivery);
186+
187+
Test.startTest();
188+
List<Database.UpsertResult> results = new ServiceDeliveryDomain()
189+
.upsertServiceDeliveries(serviceDeliveriesToUpsert, false);
190+
Test.stopTest();
191+
192+
List<ServiceDelivery__c> serviceDeliveriesAfter = [
193+
SELECT Id, Name
194+
FROM ServiceDelivery__c
195+
];
196+
System.assertEquals(
197+
existingServiceDeliveries.size() + 1,
198+
serviceDeliveriesAfter.size(),
199+
'One new record should be inserted.'
200+
);
201+
System.assertEquals(
202+
serviceDeliveriesAfter.size(),
203+
results.size(),
204+
'Results should be returned for each record upserted.'
205+
);
206+
for (ServiceDelivery__c delivery : serviceDeliveriesAfter) {
207+
System.assertEquals(
208+
'Upserted',
209+
delivery.Name,
210+
'All records should be renamed.'
211+
);
212+
}
213+
}
214+
162215
@IsTest
163216
private static void shouldThrowExceptionWhenInsertPermissionCheckFails() {
164217
String methodName = 'hasObjectAccess';

force-app/main/default/lwc/bulkServiceDeliveryUI/bulkServiceDeliveryUI.html

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,7 @@
3434
default-values={delivery}
3535
service-delivery-field-sets={serviceDeliveryFieldSets}
3636
index={delivery.index}
37-
onsuccess={handleRowSuccess}
3837
ondelete={handleRowDelete}
39-
onerror={handleRowError}
4038
row-count={rowCount}
4139
should-focus={delivery.shouldFocus}
4240
></c-service-delivery-row>

force-app/main/default/lwc/bulkServiceDeliveryUI/bulkServiceDeliveryUI.js

Lines changed: 11 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -209,37 +209,20 @@ export default class BulkServiceDeliveryUI extends NavigationMixin(LightningElem
209209
}
210210
}
211211

212-
savingComplete() {
213-
if (this.currentSaveCount - this.savedCount - this.errorCount === 0) {
214-
return true;
215-
}
216-
return false;
217-
}
218-
219212
showSaveSummaryToast() {
220213
let toastVariant = this.savingCompleteToastVariant;
221214
let toastTitle = toastVariant === "success" ? this.labels.success : "";
222215

223216
showToast(toastTitle, this.savingCompleteMessage, toastVariant, "dismissible");
224217
}
225218

226-
// eslint-disable-next-line no-unused-vars
227-
handleRowError(event) {
228-
this.errorCount++;
229-
if (this.savingComplete()) {
230-
this.showSaveSummaryToast();
231-
this.isSaving = false;
232-
}
233-
}
234-
235219
handleSave() {
236220
let rows = this.template.querySelectorAll("c-service-delivery-row");
237221
let deliveries = [];
238222

239223
this.savedCount = 0;
240224
this.errorCount = 0;
241225
this.targetSaveCount = 0;
242-
this.currentSaveCount = 0;
243226

244227
rows.forEach(row => {
245228
if (row.isDirty || row.isError) {
@@ -258,7 +241,6 @@ export default class BulkServiceDeliveryUI extends NavigationMixin(LightningElem
258241
}
259242
});
260243

261-
this.currentSaveCount = deliveries.length;
262244
if (this.targetSaveCount === 0) {
263245
this.dispatchEvent(new CustomEvent("done"));
264246
return;
@@ -268,6 +250,11 @@ export default class BulkServiceDeliveryUI extends NavigationMixin(LightningElem
268250
}
269251

270252
upsertDeliveries(deliveries) {
253+
if (deliveries.length === 0) {
254+
return;
255+
}
256+
257+
this.isSaving = true;
271258
upsertRows({
272259
serviceDeliveries: deliveries,
273260
allOrNone: false,
@@ -278,6 +265,11 @@ export default class BulkServiceDeliveryUI extends NavigationMixin(LightningElem
278265
})
279266
.catch(error => {
280267
handleError(error);
268+
})
269+
.finally(() => {
270+
this.isSaving = false;
271+
this.showSaveSummaryToast();
272+
this.dispatchEvent(new CustomEvent("done"));
281273
});
282274
}
283275

@@ -304,6 +296,7 @@ export default class BulkServiceDeliveryUI extends NavigationMixin(LightningElem
304296
let delivery = resultByIndex[row.index];
305297

306298
if (delivery.result.success) {
299+
this.savedCount++;
307300
row.handleSuccess(delivery);
308301
} else {
309302
this.errorCount++;
@@ -314,20 +307,6 @@ export default class BulkServiceDeliveryUI extends NavigationMixin(LightningElem
314307
}
315308
}
316309

317-
// eslint-disable-next-line no-unused-vars
318-
handleRowSuccess(event) {
319-
this.savedCount++;
320-
321-
if (this.savingComplete()) {
322-
this.showSaveSummaryToast();
323-
this.isSaving = false;
324-
}
325-
326-
if (this.savedCount === this.targetSaveCount) {
327-
this.dispatchEvent(new CustomEvent("done"));
328-
}
329-
}
330-
331310
handleFinishWizard(event) {
332311
this.hideWizard = true;
333312
let selectedEngagements = event.detail.selectedEngagements;

force-app/main/default/lwc/serviceDeliveryRow/serviceDeliveryRow.html

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,6 @@
1111
<div class="style-target"></div>
1212
<div class="slds-var-p-top_small hideHelpText">
1313
<lightning-record-edit-form
14-
onsuccess={handleSuccess}
15-
onsubmit={handleSubmit}
16-
onerror={handleSaveError}
1714
record-id={recordId}
1815
object-api-name={serviceDeliveryObject}
1916
>

0 commit comments

Comments
 (0)