BookatlasTwo-Day MuleSoft → Salesforce Bootcamp
77 / 81 · Module 18 — Interview Coding Scenarios · filtered: interview← prev⊞ allnext →

18.27Scenario 26 — MUnit happy-path test

Prompt:

“Write a unit test for the customer flow.”

Conceptually:

<munit:test name="customer-upsert-success">

    <munit:behavior>

        <munit-tools:mock-when
            processor="salesforce:upsert">

            <munit-tools:then-return>

                <munit-tools:payload
                    value="#[[
                        {
                            id: '001ABC',
                            success: true
                        }
                    ]]"/>

            </munit-tools:then-return>

        </munit-tools:mock-when>

    </munit:behavior>


    <munit:execution>

        <munit:set-event>
            <munit:payload
                value="#[{
                    customerId: 'C001',
                    companyName: 'Acme'
                }]"/>
        </munit:set-event>

        <flow-ref name="process-customer-flow"/>

    </munit:execution>


    <munit:validation>

        <munit-tools:assert-that
            expression="#[payload.salesforceId]"
            is="#[MunitTools::equalTo('001ABC')]"/>

        <munit-tools:verify-call
            processor="salesforce:upsert"
            times="1"/>

    </munit:validation>

</munit:test>

Again, exact XML details matter less than:

Mock
↓
Set Event
↓
Call real flow
↓
Assert
↓
Verify