Skip to content

Commit

Permalink
Fixed the fabricator tests
Browse files Browse the repository at this point in the history
Takes into account the boolean passed into serialize
  • Loading branch information
rob-baillie-ortoo committed Dec 3, 2021
1 parent 9ce7271 commit 32b1f5e
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
public class sfab_FabricatedSObjectStub extends sfab_FabricatedSObject {
private Map<String, Object> serializedMap;
@testVisible private Boolean serializeInvoked = false;
@testVisible private Boolean serializeInvokedWith = null;

public sfab_FabricatedSObjectStub(Type sType) {
super(sType);
Expand All @@ -14,6 +15,7 @@ public class sfab_FabricatedSObjectStub extends sfab_FabricatedSObject {

public override Map<String, Object> serialize( Boolean persistable ) {
serializeInvoked = true;
serializeInvokedWith = persistable;
return serializedMap;
}
}
Original file line number Diff line number Diff line change
@@ -1,42 +1,95 @@
@isTest
private class sfab_ChildRelationshipNodeTest {
@isTest
private static void serialize_expectSerializeInvokedOnChildren() {
private static void serialize_whenPassedTrue_expectSerializeInvokedOnChildren() {
sfab_FabricatedSObjectStub child1 = new sfab_FabricatedSObjectStub(Account.class);
sfab_FabricatedSObjectStub child2 = new sfab_FabricatedSObjectStub(Account.class);
sfab_ChildRelationshipNode node = new sfab_ChildRelationshipNode('Accounts__r', new List<sfab_FabricatedSObject> { child1, child2 });

node.serialize();
node.serialize( true );

System.assert(child1.serializeInvoked);
System.assert(child1.serializeInvokedWith);
System.assert(child2.serializeInvoked);
System.assert(child2.serializeInvokedWith);
}
@isTest
private static void serialize_whenPassedFalse_expectSerializeInvokedOnChildren() {
sfab_FabricatedSObjectStub child1 = new sfab_FabricatedSObjectStub(Account.class);
sfab_FabricatedSObjectStub child2 = new sfab_FabricatedSObjectStub(Account.class);
sfab_ChildRelationshipNode node = new sfab_ChildRelationshipNode('Accounts__r', new List<sfab_FabricatedSObject> { child1, child2 });

node.serialize( false );

System.assert(child1.serializeInvoked);
System.assert(!child1.serializeInvokedWith);
System.assert(child2.serializeInvoked);
System.assert(!child2.serializeInvokedWith);
}

@isTest
private static void serialize_whenPassedTrue_expectDoneMapKey() {
sfab_ChildRelationshipNode node = new sfab_ChildRelationshipNode('Accounts__r', new List<sfab_FabricatedSObject>());

Map<String, Object> builtNode = node.serialize( true );

System.assert(((Map<String, Object>)builtNode.get('Accounts__r')).containsKey('done'));
System.assert((Boolean)((Map<String, Object>)builtNode.get('Accounts__r')).get('done'));
}

@isTest
private static void serialize_whenPassedTrue_expectTotalSizeMapKey() {
sfab_ChildRelationshipNode node = new sfab_ChildRelationshipNode('Accounts__r', new List<sfab_FabricatedSObjectStub> {
new sfab_FabricatedSObjectStub(Account.class),
new sfab_FabricatedSObjectStub(Account.class)
});

Map<String, Object> builtNode = node.serialize( true );

System.assert(((Map<String, Object>)builtNode.get('Accounts__r')).containsKey('totalSize'));
System.assertEquals(2, ((Map<String, Object>)builtNode.get('Accounts__r')).get('totalSize'));
}

@isTest
private static void serialize_whenPassedTrue_expectSerializedChildrenMap() {
sfab_FabricatedSObjectStub child1 = new sfab_FabricatedSObjectStub(Account.class, new Map<String, Object> { 'Name' => 'Foo-1' });
sfab_FabricatedSObjectStub child2 = new sfab_FabricatedSObjectStub(Account.class, new Map<String, Object> { 'Name' => 'Foo-2' });
sfab_ChildRelationshipNode node = new sfab_ChildRelationshipNode('Accounts__r', new List<sfab_FabricatedSObject> { child1, child2 });

List<Map<String, Object>> serializedChildren = new List<Map<String, Object>>();
serializedChildren.add(child1.serialize());
serializedChildren.add(child2.serialize());

Map<String, Object> builtNode = node.serialize( true );

System.assertEquals(serializedChildren, ((Map<String, Object>)builtNode.get('Accounts__r')).get('records'));
}

@isTest
private static void serialize_expectDoneMapKey() {
private static void serialize_whenPassedFalse_expectDoneMapKey() {
sfab_ChildRelationshipNode node = new sfab_ChildRelationshipNode('Accounts__r', new List<sfab_FabricatedSObject>());

Map<String, Object> builtNode = node.serialize();
Map<String, Object> builtNode = node.serialize( false );

System.assert(((Map<String, Object>)builtNode.get('Accounts__r')).containsKey('done'));
System.assert((Boolean)((Map<String, Object>)builtNode.get('Accounts__r')).get('done'));
}

@isTest
private static void serialize_expectTotalSizeMapKey() {
private static void serialize_whenPassedFalse_expectTotalSizeMapKey() {
sfab_ChildRelationshipNode node = new sfab_ChildRelationshipNode('Accounts__r', new List<sfab_FabricatedSObjectStub> {
new sfab_FabricatedSObjectStub(Account.class),
new sfab_FabricatedSObjectStub(Account.class)
});

Map<String, Object> builtNode = node.serialize();
Map<String, Object> builtNode = node.serialize( false );

System.assert(((Map<String, Object>)builtNode.get('Accounts__r')).containsKey('totalSize'));
System.assertEquals(2, ((Map<String, Object>)builtNode.get('Accounts__r')).get('totalSize'));
}

@isTest
private static void serialize_expectSerializedChildrenMap() {
private static void serialize_whenPassedFalse_expectSerializedChildrenMap() {
sfab_FabricatedSObjectStub child1 = new sfab_FabricatedSObjectStub(Account.class, new Map<String, Object> { 'Name' => 'Foo-1' });
sfab_FabricatedSObjectStub child2 = new sfab_FabricatedSObjectStub(Account.class, new Map<String, Object> { 'Name' => 'Foo-2' });
sfab_ChildRelationshipNode node = new sfab_ChildRelationshipNode('Accounts__r', new List<sfab_FabricatedSObject> { child1, child2 });
Expand All @@ -45,7 +98,7 @@ private class sfab_ChildRelationshipNodeTest {
serializedChildren.add(child1.serialize());
serializedChildren.add(child2.serialize());

Map<String, Object> builtNode = node.serialize();
Map<String, Object> builtNode = node.serialize( false );

System.assertEquals(serializedChildren, ((Map<String, Object>)builtNode.get('Accounts__r')).get('records'));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
@isTest
private class sfab_FieldValuePairNodeTest {
@isTest
private static void serialize_expectMap() {
private static void serialize_whenPassedTrue_expectMap() {
sfab_FieldValuePairNode node = new sfab_FieldValuePairNode(Account.Name, 'Foo');
Map<String, Object> builtNode = node.serialize();
Map<String, Object> builtNode = node.serialize( true );

System.assertEquals(new Map<String, Object> { 'Name' => 'Foo' }, builtNode);
}
@isTest
private static void serialize_whenPassedFalse_expectMap() {
sfab_FieldValuePairNode node = new sfab_FieldValuePairNode(Account.Name, 'Foo');
Map<String, Object> builtNode = node.serialize( false );

System.assertEquals(new Map<String, Object> { 'Name' => 'Foo' }, builtNode);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,47 @@
@isTest
private class sfab_ParentRelationshipNodeTest {
@isTest
private static void serialize_expectSerializeInvokedOnParent() {
private static void serialize_whenPassedTrue_expectSerializeInvokedOnParent() {
sfab_FabricatedSObjectStub fabricatedParent = new sfab_FabricatedSObjectStub(Account.class);
sfab_ParentRelationshipNode node = new sfab_ParentRelationshipNode('Account__r', fabricatedParent);

node.serialize();
node.serialize( true );

System.assert(fabricatedParent.serializeInvoked);
System.assert(fabricatedParent.serializeInvokedWith);
}

@isTest
private static void serialize_expectSerializedParentMap() {
private static void serialize_whenPassedFalse_expectSerializeInvokedOnParent() {
sfab_FabricatedSObjectStub fabricatedParent = new sfab_FabricatedSObjectStub(Account.class);
sfab_ParentRelationshipNode node = new sfab_ParentRelationshipNode('Account__r', fabricatedParent);

node.serialize( false );

System.assert(fabricatedParent.serializeInvoked);
System.assert(!fabricatedParent.serializeInvokedWith);
}

@isTest
private static void serialize_whenPassedFalse_expectSerializedParentMap() {
sfab_FabricatedSObjectStub fabricatedParent = new sfab_FabricatedSObjectStub(Account.class, new Map<String, Object> { 'Name' => 'Foo' });
sfab_ParentRelationshipNode node = new sfab_ParentRelationshipNode('Account__r', fabricatedParent);

Map<String, Object> builtNode = node.serialize();
Map<String, Object> builtNode = node.serialize( false );

System.assertEquals(new Map<String, Object> { 'Account__r' => fabricatedParent.serialize() }, builtNode);
}

@isTest
private static void serialize_whenPassedTrue_expectSerializedParentMap() {
sfab_FabricatedSObjectStub fabricatedParent = new sfab_FabricatedSObjectStub(Account.class, new Map<String, Object> { 'Name' => 'Foo' });
sfab_ParentRelationshipNode node = new sfab_ParentRelationshipNode('Account__r', fabricatedParent);

Map<String, Object> builtNode = node.serialize( true );

System.assertEquals(new Map<String, Object>(), builtNode);
}

@isTest
private static void getName_expectParentReturned() {
sfab_FabricatedSObjectStub fabricatedParent = new sfab_FabricatedSObjectStub(Account.class, new Map<String, Object> { 'Name' => 'Foo' });
Expand Down

0 comments on commit 32b1f5e

Please sign in to comment.