forked from trailheadapps/ebikes-lwc
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
368391d
commit 9bb31b1
Showing
4 changed files
with
91 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
@isTest | ||
public class TestOrderController { | ||
|
||
public static Order__c createOrder() { | ||
Account acc = new Account( | ||
Name='Sample Account' | ||
); | ||
insert acc; | ||
|
||
Order__c newOrder = new Order__c( | ||
Account__c=acc.Id | ||
); | ||
insert newOrder; | ||
return newOrder; | ||
} | ||
|
||
public static void createOrderItem(Id orderId) { | ||
Product__c p = new Product__c( | ||
Name='Sample Product' | ||
); | ||
insert p; | ||
Order_Item__c orderItem = new Order_Item__c( | ||
Order__c=orderId, | ||
Product__c=p.Id | ||
); | ||
insert orderItem; | ||
} | ||
|
||
static testMethod void testGetOrderItems() { | ||
Order__c newOrder = TestOrderController.createOrder(); | ||
Id orderId = newOrder.Id; | ||
TestOrderController.createOrderItem(orderId); | ||
Test.startTest(); | ||
List<Order_Item__c> orderItems = OrderController.getOrderItems(orderId); | ||
Test.stopTest(); | ||
System.assertEquals(orderItems.size(), 1); | ||
} | ||
|
||
} |
5 changes: 5 additions & 0 deletions
5
force-app/main/default/classes/TestOrderController.cls-meta.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<ApexClass xmlns="urn:metadata.tooling.soap.sforce.com" fqn="TestOrderController"> | ||
<apiVersion>45.0</apiVersion> | ||
<status>Active</status> | ||
</ApexClass> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
@isTest | ||
public class TestProductController { | ||
|
||
public static void createProducts() { | ||
List<Product__c> products = new List<Product__c>(); | ||
|
||
products.add(new Product__c( | ||
Name='Sample Bike 1', | ||
MSRP__c=1000, | ||
Category__c='Mountain', | ||
Level__c='Beginner', | ||
Material__c='Carbon')); | ||
|
||
products.add(new Product__c( | ||
Name='Sample Bike 2', | ||
MSRP__c=1200, | ||
Category__c='Mountain', | ||
Level__c='Beginner', | ||
Material__c='Carbon')); | ||
|
||
insert products; | ||
} | ||
|
||
static testMethod void testGetProducts() { | ||
TestProductController.createProducts(); | ||
String filters = '{"searchKey":"Sample", "maxPrice":2000, "categories": ["Mountain"], "levels": ["Beginner"], "materials":["Carbon"]}, 1'; | ||
Test.startTest(); | ||
PagedResult result = ProductController.getProducts(filters, 1); | ||
Test.stopTest(); | ||
System.assertEquals(result.records.size(), 2); | ||
} | ||
static testMethod void testGetSimilarProducts() { | ||
TestProductController.createProducts(); | ||
Test.startTest(); | ||
String filters = '{"searchKey":"Sample", "maxPrice":2000, "categories": ["Mountain"], "levels": ["Beginner"], "materials":["Carbon"]}, 1'; | ||
PagedResult result = ProductController.getProducts(filters, 1); | ||
Product__c productToCompare = (Product__c)result.records[0]; | ||
Product__c[] products = ProductController.getSimilarProducts(productToCompare.Id, null); | ||
System.assertEquals(products.size(), 1); | ||
} | ||
|
||
} |
5 changes: 5 additions & 0 deletions
5
force-app/main/default/classes/TestProductController.cls-meta.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<ApexClass xmlns="urn:metadata.tooling.soap.sforce.com" fqn="TestProductController"> | ||
<apiVersion>45.0</apiVersion> | ||
<status>Active</status> | ||
</ApexClass> |