mr-kenikh/nestjs-mongoose-discriminators

Problem: resource service test fails

Closed this issue · 0 comments

Resource schema has a field msgs that contains an array of messages: MsgAlert, MsgInfo or MsgWarn (each implements Msg). But in-array properties are not cast to the associated SchemaType:

ResourceService › should be casted

    - Expected  - 1
    + Received  + 1

    @@ -1,11 +1,11 @@
      Object {
        "index": 0,
        "msgs": Array [
          Object {
            "action": "wipe",
    -       "instance_id": 0,
    +       "instance_id": "0",
            "type": "alert",
          },
          Object {
            "info": "success",
            "type": "info",

The problem is that value field of discriminator mapping has null value, although alert, info or warn is expected:

ResourceService › should match discriminator mapping

    - Expected  - 3
    + Received  + 3

      Array [
        Object {
          "isRoot": true,
          "key": "type",
    -     "value": "alert",
    +     "value": null,
        },
        Object {
          "isRoot": true,
          "key": "type",
    -     "value": "info",
    +     "value": null,
        },
        Object {
          "isRoot": true,
          "key": "type",
    -     "value": "warn",
    +     "value": null,
        },
      ]

Tests of the msg service passes successfully, there is no problem with discriminator mapping.