Skip to content

Integration testing the Xrm.WebApi implementation

Scott Durow edited this page Nov 22, 2022 · 4 revisions

Note: These wiki pages have been deprecated and only apply to version 1. Please refer to the latest documentation.

Dataverseify comes with an implementation of the Xrm.WebApi that can be run in native node tests:

To setup, simply:

  1. At the root of your project, add a folder name 'config'
  2. Add a file test.yaml
# Configuration file for the XrmNode Unit tests
nodewebapi:
 server:
  host: https://someorg.crm3.dynamics.com
  version: 9.1
  1. Add a test along the lines of:
import { SetupGlobalContext } from "dataverse-ify/lib/webapi";
test("retrieveMultipleRecords", async () => {
  await SetupGlobalContext();
  const fetch = `<fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="false">
  <entity name="my_entity">
    <attribute name="my_attribute" />
  </entity>
</fetch>`;
  const response = await Xrm.WebApi.retrieveMultipleRecords(
    "my_entity",
    "?fetchXml=" + encodeURIComponent(fetch),
  );
  console.log(response);
});

You will need to run dataverse-auth for the server you are using so that the authentication token is present locally:

npx dataverse-auth someorg.api.crm4.dynamics.com

When you run the test, the dataverseify implementation of the WebApi will be used and so you can run integration tests as though they were running inside the browser!

It's worth noting that this does not need any metadata generated until you start using the dataverseify odataify and sdkify.

Clone this wiki locally