Code Monkey home page Code Monkey logo

apextestkit's People

Contributors

inksword avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

apextestkit's Issues

Stack limitation exception is raised when debug level is finest

Stack limitation exception is raised when Apex debug level is finest, here is how to reproduce the issue:

  1. Change Apex debug level to Finest
  2. Run the following scripts:
ATK.SaveResult result = ATK.prepare(Account.SObjectType, 1)
    .withChildren(Contact.SObjectType, Contact.AccountId, 1)
    .mock();

Other Apex debug level will have no such problem.

=====================Known SF Issue======================
https://trailblazer.salesforce.com/issues_view?id=a1p3A000001Gv4KQAS

Mock method backward compatibility 3.3.1 and 3.4.1 versions

Using 3.3.1 version the next code gives the result:

Id userId = '005000000000003AAA';
Id managerId = '005000000000004AAA';
List<User> users = (List<User>) ATK.prepare(User.SObjectType, 1)
        .profile('System Administrator')
        .field(User.Id).repeat(userId)
        .field(User.LastName).repeat('userLastName')
        .field(User.Name).repeat('userName')
        .field(User.ManagerId).repeat(managerId)
        .mock()
        .get(User.SObjectType);
System.debug(LoggingLevel.INFO, 'users ' + JSON.serializePretty(users));
/*
{
  "attributes" : {
    "type" : "User",
    "url" : "/services/data/v51.0/sobjects/User/005000000000003AAA"
  },
  "ProfileId" : "00e1j000000htRQAAY",
  "Id" : "005000000000003AAA",
  "LastName" : "userLastName",
  "ManagerId" : "005000000000004AAA",
  "Name" : "userName"
}
*/

Using 3.4.1 version the next code gives the result:

Id userId = '005000000000003AAA';
Id managerId = '005000000000004AAA';
List<User> users = (List<User>) ATK.prepare(User.SObjectType, 1)
        .profile('System Administrator')
        .field(User.Id).repeat(userId)
        .field(User.LastName).repeat('userLastName')
        .field(User.Name).repeat('userName')
        .field(User.ManagerId).repeat(managerId)
        .mock()
        .get(User.SObjectType);
System.debug(LoggingLevel.INFO, 'users ' + JSON.serializePretty(users));
/*
{
  "attributes" : {
    "type" : "User",
    "url" : "/services/data/v51.0/sobjects/User/005000zzzz00001AAA"
  },
  "ProfileId" : "00e1j000000htRQAAY",
  "Id" : "005000zzzz00001AAA",
  "LastName" : "userLastName",
  "ManagerId" : "005000000000004AAA",
  "Name" : "userName"
}
*/

Somehow in 3.4.1 the User.Id field is being overridden by the newly generated Id value regardless we use .field(User.Id).repeat(userId) method invocation or not. Although ManagerId lookup wasn't overridden.
Is it expected behavior and what should we do in case if we want to set the Id from the outside?
I've raised the issue at least because the 3.4.1 version breaks the backward compatibility with 3.3.1 for such a specific scenario.

[proposal] the save method should use "true" implicitly

This proposal is to make the main ATK class to contain two save methods. One with a boolean in its signature (which is the one present today) and another one without parameters, that implies that the developer wants to save the records ("true" is used).

v4.0 with BDD

Will bring java mockito library BDD API into ATK. Something like the following will be implemented. The feature is still in its early design/development phase, please leave comments if some features want to be considered. You can also suggest how to define the APIs if they are more concise. Target to deliver in August this year 2021.

SomeClassOrInterface mock = (SomeClassOrInterface)ATK.mock(SomeClassOrInterface.class);
{// GIVEN
    ATK.given(mock.doWithInteger(0)).willReturn(0);
    ATK.given(mock.doWithInteger(ATK.anyInteger())).willReturn(1);
    ATK.given(mock.doWithInteger(2)).willAnswer(new IntegerAnswer());
    ATK.given(mock.doWithInteger(3)).willThrow(exp);

    ((ATKMockTest)ATK.willReturn(4).given(mock)).doWithInteger(4);
    ((ATKMockTest)ATK.willThrow(exp).given(mock)).doException(); // void method
    ((ATKMockTest)ATK.willDoNothing().given(mock)).doNothing();  // void method
}

{// WHEN
    mock.doWithInteger(0);
    mock.doWithInteger(1);
    mock.doWithInteger(2);
    try {
        mock.doWithInteger(3);
    } catch (MockException ex) {
    }
    mock.doWithInteger(4);

    try {
        mock.doException();
    } catch (MockException ex) {
    }
    mock.doNothing();
}

{// THEN
    ((ATKMockTest)ATK.then(mock).should().times(1)).doWithInteger(0);
    ((ATKMockTest)ATK.then(mock).should().atLeast(1)).doWithInteger(ATK.anyInteger());
    ((ATKMockTest)ATK.then(mock).should().atMost(1)).doWithInteger(2);
    ((ATKMockTest)ATK.then(mock).should().never()).doWithInteger(5);

    ATK.InOrder inOrder = ATK.inOrder(mock);
    ((ATKMockTest)ATK.then(mock).should(inOrder).times(1)).doWithInteger(0);
    ((ATKMockTest)ATK.then(mock).should(inOrder).atLeast(1)).doWithInteger(ATK.anyInteger());
    ((ATKMockTest)ATK.then(mock).should(inOrder).times(1)).doWithInteger(2);
    ((ATKMockTest)ATK.then(mock).should(inOrder).times(1)).doWithInteger(3);
}

I feel it is very encouraging when stars go up, and also a big thank-you for you to choose this library.

ContentVersion generation error: FIELD_INTEGRITY_EXCEPTION

System.DmlException: Insert failed. First exception on row 0; first error: FIELD_INTEGRITY_EXCEPTION, We can't enable this file because its file type isn't allowed for asset files.: [FileType]

ATKWizard.I().wantMany('ContentVersion')
    .total(3)
    .fields(new Map<String, Object> {
        'Title' => 'file_title_{{###}}',
        'PathOnClient' => 'file_path_{{###}}',
        'VersionData' => EncodingUtil.base64Decode('Unit Test Attachment Body')
    })
    .generate();

Suspect some of the required fields are not generated correctly.

Dependent picklist value assignment is not based on its controlling field

As discussed with colleague today. I realized, the library doesn't support dependent field selection. With a bit of search online, I am going to follow the strategy mentioned in:

Just to think one step further, how about select picklist values based on record types? However, after googling it, this can only be achieved from User Interface API, or Metadata API, which are not an option during unit testing.

Failing test_Util_Converter test case

We're installed this package on our org. The test case test_Util_Converter is failing on this line.
It could be a timezone thing, since the default timezone is Chicago time.

Error message: | System.AssertException: Assertion Failed: Expected: 2021-01-16, Actual: 2021-01-15
-- | --
Stack trace: | Class.ATKCoreTest.test_Util_Converter: line 972, column 1

Field value can be computed from the value of a previous record

After discussion with my colleague, they sometime have to create records based on sequential dates. For example:

  1. record (from: 2018-1-1, to: 2018-1-31)
  2. record (from: 2018-2-1, to: 2018-2-30)
  3. record (from: 2018-3-1, to: 2018-3-31)
  4. and so on...

Initially, I think this could not be possible. But after a second thought, I came up with some immature ideas. I can create some arithmetic expressions along side with a parameter pattern to reference dynamic record such as

  1. $0 (current record)
  2. $1 (the record before current record)
  3. $2 (the record before $1)
  4. and so on...
fields(new Map<String, Object> {
    'StartDate__c' => '{!dates.addDay($1.EndDate__c, 1)}',
    'EndDate__c' => '{!dates.addMonth($1.EndDate__c, 1)}',
    'Bigger__c' => '{!number.add($0.Smaller__c, 10)}'
})

Could this be useful? or it just complicates the generation logic. Anything simpler can be achieved?

Get children list is empty when using save, save(false) or mock

After creating an object with children, object.childrens is empty.
For example:

    List<Account> accountMocks = (List<Account>) ATK.prepare(Account.SObjectType, 1)
            .field(Account.Name).repeat('Name')
                .withChildren(Contact.SObjectType, Contact.AccountId, 1)
            .mock().get(Account.SObjectType);
    System.debug(accountMocks[0]);  //Account:{Name=Name, Id=001000zzzz00001AAA}
    System.debug(accountMocks[0].Contacts); //()

    List<Account> accountsSavedFalse = (List<Account>) ATK.prepare(Account.SObjectType, 1)
            .field(Account.Name).repeat('Name')
                .withChildren(Contact.SObjectType, Contact.AccountId, 1)
            .save(false).get(Account.SObjectType);
    System.debug(accountsSavedFalse[0]); //Account:{Name=Name}
    System.debug(accountsSavedFalse[0].Contacts); //()

    List<Account> accountsSaved = (List<Account>) ATK.prepare(Account.SObjectType, 1)
            .field(Account.Name).repeat('Name')
                .withChildren(Contact.SObjectType, Contact.AccountId, 1)
            .save().get(Account.SObjectType);
    System.debug(accountsSaved[0]); //Account:{Name=Name, Id=0011X00000jKZvoQAG}
    System.debug(accountsSaved[0].Contacts);    //()

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.