Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test serializers using factories. #412

Open
far-fetched opened this issue Jan 31, 2020 · 3 comments
Open

Test serializers using factories. #412

far-fetched opened this issue Jan 31, 2020 · 3 comments

Comments

@far-fetched
Copy link

Hello,
During serialization / normalization tests I have encountered a problem, which I am not sure is possible to resolve. Ofc I would like to use factories.
E.g. I test my serializer, using expected payload from server.

this.store.normalize('model', payload);

Using make / build I can create objects which depend on models - usually fairly distinct from server response payload. Let's suppose I have old system without rest, json-api conventions.
My member factory method (build) returns:

{ 
   id: 1,
   name: 'member1',
   group: 1
}

But serializer needs sth like:

{
   member: {
      id: 1
   },
   group: {
      id: 1
   }
}

I was wondering about sth like:

build('member').payload()

and define additional hook in factory e.g.

FactoryGuy.define('member', {
   default: {
      ...
   },
   payload(member) {
      return {
         member: member,
         group: member.group 
      }
   }

WDYT ? Any possible solutions, ideas ?

@danielspaniel
Copy link
Collaborator

danielspaniel commented Jan 31, 2020

I am not exactly sure what you need
but factory guy has

mockAny({url: "http://blah", responseText: {whatever the heck you want}).

see here the tests for it .. because YIKES ,, it is not documented!

@far-fetched
Copy link
Author

Hmm ok sounds reasonable.
If you mentioned mock* functions...
Is it any simple way of testing pending states using mock* helpers ?

Pseudo test idea:

let request = mockFindAll('comment'); // don't specify what endpoint returns 
let response = commentService.findAllWithSpinner(); //adapter 'findAll' returns pending promise

// here test spinner is visible

request.resolve(comments);
await response;

// here test spinner is hidden

assert.ok(response.value);

@danielspaniel
Copy link
Collaborator

I don't know man .. if you can make a PR for this that is clean .. i would take it .. but not so easy.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants