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

Add tests for generated models #68

Closed
maicki opened this issue Jul 25, 2017 · 0 comments
Closed

Add tests for generated models #68

maicki opened this issue Jul 25, 2017 · 0 comments

Comments

@maicki
Copy link
Contributor

maicki commented Jul 25, 2017

We should add tests for our generated models to make changes way more safer and see immediately if we break something.

We should look into adding the tests to the Example/ folder and we could swift test for that project.

I ran into the issue in #67 as I wanted to be sure that the model dictionary is the same as calling dictionaryRepresentation on it. The tests could look like something like that:

NSDictionary *imageModelDictionary = @{
    @"height" : @(12),
    @"width" : @(11),
    @"url" : @"http://google.com"
};
Image *image = [[Image alloc] initWithModelDictionary:imageModelDictionary];
XCTAssert([imageModelDictionary isEqualToDictionary:[image dictionaryRepresentation]], @"Should be the same");


NSDictionary *userModelDictionary = @{
    @"id" : @(123),
    @"first_name" : @"Michael",
    @"last_name" : @"Schneider",
    @"image" : imageModelDictionary,
};
User *user = [[User alloc] initWithModelDictionary:userModelDictionary];
XCTAssert([userModelDictionary isEqualToDictionary:[user dictionaryRepresentation]], @"Should be the same");
var imageModelDictionary: [AnyHashable: Any] = ["height": (12), "width": (11), "url": "http://google.com"]
var image = Image(modelDictionary: imageModelDictionary)
XCTAssert(imageModelDictionary.isEqual(to: image.dictionaryRepresentation), "Image dictionary representation should be the same as the model dictionary.")
var userModelDictionary: [AnyHashable: Any] = ["id": (123), "first_name": "Michael", "last_name": "Schneider", "image": imageModelDictionary]
var user = User(modelDictionary: userModelDictionary)
XCTAssert(userModelDictionary.isEqual(to: user.dictionaryRepresentation), "User dictionary representation should be the same as the model dictionary")
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