0

my consumer service asks a provider service for a list of all users, but the provider answers with an arbitrary ordered list (which is fine). The pact execution on consumer side looks fine, but when executing it on the provider site, it says: Expected "user1" but got "user3" at $.items[0].userName for example.

This is is a snippet of the interaction:

willRespondWith: {
    status: 200,
    headers: { "Content-Type": "application/json; charset=utf-8" },
    body: {
        items: [
            { userName: "user1" },
            { userName: "user2" },
            { userName: "user3" },
        ],
    },
},

Is there a way to ignore the order of returned items?

Further, my mocha test doesn't seem to have an impact on the comparison. I also tried to order both arrays, but nothing helped. How are both (interaction and mocha test) connected?

it("Should generate a list of users in the system", async function () {
            await userServiceClient.getUsers()
                .then((users) => {
                    expect(users).to.include.members(EXPECTED_USERS_ARRAY);
                });
});

Many thanks in advance!

J_A_X
  • 12,857
  • 1
  • 25
  • 31
S. Duclos
  • 3
  • 1
  • 2
  • Can I ask what's the benefit of comparing the name order to make sure it's correct? – J_A_X Sep 21 '17 at 23:10
  • To just make sure that every user you ask for is in the system. It's not that important since we're talking here about tests. I just wanted to know if there is such a feature. It then would make it a bit easier than the way described below. – S. Duclos Sep 24 '17 at 17:31

1 Answers1

3

This functionality isn't currently implemented, however, I would suggest using a Pact.eachLike, which will just match on types. The actual values of the fields are rarely important.

Beth Skurrie
  • 1,333
  • 7
  • 8