-
Notifications
You must be signed in to change notification settings - Fork 536
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Use serializers to generate JSON responses * Add new files to cleanup script
- Loading branch information
1 parent
a3979dc
commit 6116c5f
Showing
5 changed files
with
78 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
const UserSerializer = { | ||
serialize({ id, name }) { | ||
return { | ||
id, | ||
name | ||
}; | ||
} | ||
}; | ||
|
||
module.exports = UserSerializer; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
const { expect } = require('chai'); | ||
const UserSerializer = require('src/interfaces/http/user/UserSerializer'); | ||
const User = require('src/domain/user/User'); | ||
|
||
describe('Interfaces :: HTTP :: User :: UserSerializer', () => { | ||
it('returns id and name', () => { | ||
const serializedUser = UserSerializer.serialize({ | ||
id: 123, | ||
name: 'The User' | ||
}); | ||
|
||
expect(serializedUser).to.eql({ | ||
id: 123, | ||
name: 'The User' | ||
}); | ||
}); | ||
|
||
it('ignores extra attributes', () => { | ||
const serializedUser = UserSerializer.serialize({ | ||
id: 321, | ||
name: 'The User', | ||
unknown: 'Hello!' | ||
}); | ||
|
||
expect(serializedUser).to.eql({ | ||
id: 321, | ||
name: 'The User' | ||
}); | ||
}); | ||
|
||
it('is able to serialize user entity instances', () => { | ||
const user = new User({ id: 1, name: 'User :)' }); | ||
const serializedUser = UserSerializer.serialize(user); | ||
|
||
expect(serializedUser).to.eql({ | ||
id: 1, | ||
name: 'User :)' | ||
}); | ||
}); | ||
}); |