@@ -32,7 +32,10 @@ describe("POST /bake", function() {
3232 . post ( "/bake" )
3333 . send ( { input : "testing, one two three" , recipe : [ ] } )
3434 . expect ( 200 )
35- . expect ( "testing, one two three" , done ) ;
35+ . expect ( {
36+ value : "testing, one two three" ,
37+ type : "string" ,
38+ } , done ) ;
3639 } ) ;
3740
3841 it ( "should parse the recipe if it is a valid operation name" , ( done ) => {
@@ -41,7 +44,10 @@ describe("POST /bake", function() {
4144 . set ( "Content-Type" , "application/json" )
4245 . send ( { input : "hello" , recipe : "To Hexdump" } )
4346 . expect ( 200 )
44- . expect ( "00000000 68 65 6c 6c 6f |hello|" , done ) ;
47+ . expect ( {
48+ value : "00000000 68 65 6c 6c 6f |hello|" ,
49+ type : "string" ,
50+ } , done ) ;
4551 } ) ;
4652
4753 it ( "should parse the recipe if it is a valid operation name string" , ( done ) => {
@@ -50,7 +56,10 @@ describe("POST /bake", function() {
5056 . set ( "Content-Type" , "application/json" )
5157 . send ( { input : "hello" , recipe : "toHexdump" } )
5258 . expect ( 200 )
53- . expect ( "00000000 68 65 6c 6c 6f |hello|" , done ) ;
59+ . expect ( {
60+ value : "00000000 68 65 6c 6c 6f |hello|" ,
61+ type : "string" ,
62+ } , done ) ;
5463 } ) ;
5564
5665 it ( "should parse the recipe if it is an array of operation names" , ( done ) => {
@@ -59,7 +68,10 @@ describe("POST /bake", function() {
5968 . set ( "Content-Type" , "application/json" )
6069 . send ( { input : "Testing, 1 2 3" , recipe : [ "to decimal" , "MD5" , "to braille" ] } )
6170 . expect ( 200 )
62- . expect ( "⠲⠆⠙⠋⠲⠆⠶⠶⠖⠶⠖⠙⠋⠶⠉⠆⠃⠲⠂⠑⠲⠢⠲⠆⠲⠒⠑⠶⠲⠢⠋⠃" , done ) ;
71+ . expect ( {
72+ value : "⠲⠆⠙⠋⠲⠆⠶⠶⠖⠶⠖⠙⠋⠶⠉⠆⠃⠲⠂⠑⠲⠢⠲⠆⠲⠒⠑⠶⠲⠢⠋⠃" ,
73+ type : "string" ,
74+ } , done ) ;
6375 } ) ;
6476
6577 it ( "should parse the recipe if it is an operation with some custom arguments" , ( done ) => {
@@ -68,7 +80,10 @@ describe("POST /bake", function() {
6880 . set ( "Content-Type" , "application/json" )
6981 . send ( { input : "Testing, 1 2 3" , recipe : { op : "to hex" , args : { delimiter : "Colon" } } } )
7082 . expect ( 200 )
71- . expect ( "54:65:73:74:69:6e:67:2c:20:31:20:32:20:33" , done ) ;
83+ . expect ( {
84+ value : "54:65:73:74:69:6e:67:2c:20:31:20:32:20:33" ,
85+ type : "string" ,
86+ } , done ) ;
7287 } ) ;
7388
7489 it ( "should parse the recipe if it is an operation with no custom arguments" , ( done ) => {
@@ -77,7 +92,10 @@ describe("POST /bake", function() {
7792 . set ( "Content-Type" , "application/json" )
7893 . send ( { input : "Testing, 1 2 3" , recipe : { op : "to hex" } } )
7994 . expect ( 200 )
80- . expect ( "54 65 73 74 69 6e 67 2c 20 31 20 32 20 33" , done ) ;
95+ . expect ( {
96+ value : "54 65 73 74 69 6e 67 2c 20 31 20 32 20 33" ,
97+ type : "string" ,
98+ } , done ) ;
8199 } ) ;
82100
83101 it ( "should parse a recipe in the compact JSON format taken from the CyberChef website" , ( done ) => {
@@ -86,7 +104,10 @@ describe("POST /bake", function() {
86104 . set ( "Content-Type" , "application/json" )
87105 . send ( { input : "some input" , recipe : [ { "op" : "To Morse Code" , "args" : [ "Dash/Dot" , "Backslash" , "Comma" ] } , { "op" : "Hex to PEM" , "args" : [ "SOMETHING" ] } , { "op" : "To Snake case" , "args" : [ false ] } ] } )
88106 . expect ( 200 )
89- . expect ( "begin_something_anananaaaaak_da_aaak_da_aaaaananaaaaaaan_da_aaaaaaanan_da_aaak_end_something" , done ) ;
107+ . expect ( {
108+ value : "begin_something_anananaaaaak_da_aaak_da_aaaaananaaaaaaan_da_aaaaaaanan_da_aaak_end_something" ,
109+ type : "string" ,
110+ } , done ) ;
90111 } ) ;
91112
92113 it ( "should parse a recipe ib the clean JSON format taken from the CyberChef website" , ( done ) => {
@@ -102,7 +123,10 @@ describe("POST /bake", function() {
102123 "args" : [ false ] }
103124 ] } )
104125 . expect ( 200 )
105- . expect ( "begin_something_anananaaaaak_da_aaak_da_aaaaananaaaaaaan_da_aaaaaaanan_da_aaak_end_something" , done ) ;
126+ . expect ( {
127+ value : "begin_something_anananaaaaak_da_aaak_da_aaaaananaaaaaaan_da_aaaaaaanan_da_aaak_end_something" ,
128+ type : "string" ,
129+ } , done ) ;
106130 } ) ;
107131
108132 it ( "should return a useful error if we give an input/recipe combination that results in an OperationError" , ( done ) => {
@@ -122,4 +146,49 @@ describe("POST /bake", function() {
122146 . expect ( "Invalid key length: 2 bytes\n\nThe following algorithms will be used based on the size of the key:\n 16 bytes = AES-128\n 24 bytes = AES-192\n 32 bytes = AES-256" , done ) ;
123147 } ) ;
124148
149+ it ( "should return a string output as a byte array, if outputType is defined" , ( done ) => {
150+ request ( app )
151+ . post ( "/bake" )
152+ . set ( "Content-Type" , "application/json" )
153+ . send ( {
154+ input : "irregular alcove" ,
155+ recipe : "to hex" ,
156+ outputType : "byte array" ,
157+ } )
158+ . expect ( 200 )
159+ . expect ( {
160+ value : [ 54 , 57 , 32 , 55 , 50 , 32 , 55 , 50 , 32 , 54 , 53 , 32 , 54 , 55 , 32 , 55 , 53 , 32 , 54 , 99 , 32 , 54 , 49 , 32 , 55 , 50 , 32 , 50 , 48 , 32 , 54 , 49 , 32 , 54 , 99 , 32 , 54 , 51 , 32 , 54 , 102 , 32 , 55 , 54 , 32 , 54 , 53 ] ,
161+ type : "byteArray" ,
162+ } , done ) ;
163+ } ) ;
164+
165+ it ( "should return a json output as a number, if outputType is defined" , ( done ) => {
166+ request ( app )
167+ . post ( "/bake" )
168+ . set ( "Content-Type" , "application/json" )
169+ . send ( {
170+ input : "something oddly colourful" ,
171+ recipe : "entropy" ,
172+ outputType : "number" ,
173+ } )
174+ . expect ( 200 )
175+ . expect ( {
176+ value : 3.893660689688185 ,
177+ type : "number" ,
178+ } , done ) ;
179+ } ) ;
180+
181+ it ( "should return a useful error if returnType is given but has an invalid value" , ( done ) => {
182+ request ( app )
183+ . post ( "/bake" )
184+ . set ( "Content-Type" , "application/json" )
185+ . send ( {
186+ input : "irregular alcove" ,
187+ recipe : "to hex" ,
188+ outputType : "some invalid type" ,
189+ } )
190+ . expect ( 400 )
191+ . expect ( "Invalid data type string. No matching enum." , done ) ;
192+ } ) ;
193+
125194} ) ;
0 commit comments