@leansdk/leanrc
Version:
LeanRC is a MVC framework for creating graceful applications
104 lines (102 loc) • 3.51 kB
text/coffeescript
{ expect, assert } = require 'chai'
sinon = require 'sinon'
LeanRC = require.main.require 'lib'
{
FuncG, SubsetG
RecordInterface
Utils: { co }
} = LeanRC::
describe 'HttpSerializerMixin', ->
describe '#normalize', ->
facade = null
afterEach ->
facade?.remove?()
it "should normalize object value", ->
co ->
KEY = 'TEST_HTTP_SERIALIZER_001'
facade = LeanRC::Facade.getInstance KEY
class Test extends LeanRC
class TestsCollection extends LeanRC::Collection
LeanRC::MemoryCollectionMixin
Test
class TestRecord extends LeanRC::Record
Test
findRecordByName: FuncG(String, SubsetG RecordInterface),
default: (asType) -> TestRecord
string: String
number: Number
boolean: Boolean
class HttpSerializer extends LeanRC::Serializer
LeanRC::HttpSerializerMixin
Test
boundCollection = TestsCollection.new 'TestsCollection',
delegate: 'TestRecord'
facade.registerProxy boundCollection
serializer = HttpSerializer.new boundCollection
record = yield serializer.normalize TestRecord,
type: 'Test::TestRecord'
string: 'string'
number: 123
boolean: yes
assert.instanceOf record, TestRecord, 'Normalize is incorrect'
assert.include record,
type: 'Test::TestRecord'
string: 'string'
number: 123
boolean: yes
yield return
describe '#serialize', ->
facade = null
afterEach ->
facade?.remove?()
it "should serialize Record.prototype value", ->
co ->
KEY = 'TEST_HTTP_SERIALIZER_002'
facade = LeanRC::Facade.getInstance KEY
class Test extends LeanRC
class TestsCollection extends LeanRC::Collection
LeanRC::MemoryCollectionMixin
Test
class TestRecord extends LeanRC::Record
Test
findRecordByName: FuncG(String, SubsetG RecordInterface),
default: (asType) -> TestRecord
string: String
number: Number
boolean: Boolean
class HttpSerializer extends LeanRC::Serializer
LeanRC::HttpSerializerMixin
Test
boundCollection = TestsCollection.new 'TestsCollection',
delegate: 'TestRecord'
facade.registerProxy boundCollection
serializer = HttpSerializer.new boundCollection
data = yield serializer.serialize TestRecord.new {
type: 'Test::TestRecord'
string: 'string'
number: 123
boolean: yes
}, boundCollection
assert.instanceOf data, Object, 'Serialize is incorrect'
assert.include data.test,
type: 'Test::TestRecord'
string: 'string'
number: 123
boolean: yes
yield return