@@ -4,6 +4,12 @@ const assert = require('./assert');
44
55describe ( 'Serialize' , ( ) => {
66 describe ( 'using callback' , ( ) => {
7+ const JSONSerializeAdapter = {
8+ name : 'json' ,
9+ mediaTypes : [ 'application/json' ] ,
10+ serialize : ( { api, namespace } ) => Promise . resolve ( JSON . stringify ( namespace . serialiser . serialise ( api ) ) ) ,
11+ } ;
12+
713 it ( 'errors with unknown mediaType' , ( done ) => {
814 const fury = new Fury ( ) ;
915 const api = new fury . minim . elements . Category ( ) ;
@@ -34,11 +40,7 @@ describe('Serialize', () => {
3440
3541 it ( 'can serialize with matching adapter' , ( done ) => {
3642 const fury = new Fury ( ) ;
37- fury . use ( {
38- name : 'json' ,
39- mediaTypes : [ 'application/json' ] ,
40- serialize : ( { api, namespace } ) => Promise . resolve ( JSON . stringify ( namespace . serialiser . serialise ( api ) ) ) ,
41- } ) ;
43+ fury . use ( JSONSerializeAdapter ) ;
4244
4345 const api = new fury . minim . elements . Category ( ) ;
4446
@@ -48,6 +50,17 @@ describe('Serialize', () => {
4850 done ( ) ;
4951 } ) ;
5052 } ) ;
53+
54+ it ( 'can serialize undefined `api` by creating default category' , ( done ) => {
55+ const fury = new Fury ( ) ;
56+ fury . use ( JSONSerializeAdapter ) ;
57+
58+ fury . serialize ( { api : undefined , mediaType : 'application/json' } , ( error , result ) => {
59+ expect ( error ) . to . be . null ;
60+ expect ( result ) . to . equal ( '{"element":"category"}' ) ;
61+ done ( ) ;
62+ } ) ;
63+ } ) ;
5164 } ) ;
5265
5366 describe ( 'using async/await' , ( ) => {
0 commit comments