11const Printer = require ( '../../src' ) ;
22const amqpConfig = require ( '../configs/amqp' ) ;
33
4- describe ( 'render action' , ( ) => {
5- let send ;
4+ describe ( 'render action' , async ( ) => {
5+ let service ;
6+ let amqpClient ;
67
78 // jasmine global var
89 // eslint-disable-next-line no-undef
910 jasmine . DEFAULT_TIMEOUT_INTERVAL = 30000 ;
1011
11- beforeAll ( ( ) => {
12- const service = this . service = new Printer ( { ...amqpConfig } ) ;
12+ function send ( route , message , timeout = 15000 ) {
13+ return amqpClient . publishAndWait ( route , message , { timeout } ) ;
14+ }
1315
14- return service
15- . connect ( )
16- . tap ( ( ) => {
17- const amqp = this . amqp = service . amqp ;
18-
19- send = function _send ( route , message , timeout = 15000 ) {
20- return amqp . publishAndWait ( route , message , { timeout } ) ;
21- } ;
22- } ) ;
16+ beforeAll ( async ( ) => {
17+ service = new Printer ( { ...amqpConfig } ) ;
18+ await service . connect ( ) ;
19+ amqpClient = service . amqp ;
2320 } ) ;
2421
2522 it ( 'should render & return documents' , async ( ) => {
@@ -31,10 +28,19 @@ describe('render action', () => {
3128 meta : false ,
3229 } ;
3330
34- return send ( 'pdf.render' , message )
35- . tap ( ( data ) => {
36- expect ( data ) . toMatch ( / ^ ( [ A - Z a - z 0 - 9 + / ] { 4 } ) * ( [ A - Z a - z 0 - 9 + / ] { 4 } | [ A - Z a - z 0 - 9 + / ] { 3 } = | [ A - Z a - z 0 - 9 + / ] { 2 } = = ) $ / ) ;
37- } ) ;
31+ const data = await send ( 'pdf.render' , message ) ;
32+ expect ( data ) . toMatch ( / ^ ( [ A - Z a - z 0 - 9 + / ] { 4 } ) * ( [ A - Z a - z 0 - 9 + / ] { 4 } | [ A - Z a - z 0 - 9 + / ] { 3 } = | [ A - Z a - z 0 - 9 + / ] { 2 } = = ) $ / ) ;
33+ } ) ;
34+
35+ it ( 'should render & return documents: cyrillic' , async ( ) => {
36+ const message = {
37+ template : 'font' ,
38+ context : { } ,
39+ meta : false ,
40+ } ;
41+
42+ const data = await send ( 'pdf.render' , message ) ;
43+ expect ( data ) . toMatch ( / ^ ( [ A - Z a - z 0 - 9 + / ] { 4 } ) * ( [ A - Z a - z 0 - 9 + / ] { 4 } | [ A - Z a - z 0 - 9 + / ] { 3 } = | [ A - Z a - z 0 - 9 + / ] { 2 } = = ) $ / ) ;
3844 } ) ;
3945
4046 it ( 'should render & upload document' , async ( ) => {
@@ -55,13 +61,31 @@ describe('render action', () => {
5561 } ,
5662 } ;
5763
58- return send ( 'pdf.render' , message )
59- . tap ( ( data ) => {
60- expect ( data ) . toMatch ( / ^ [ 0 - 9 A - F ] { 8 } - [ 0 - 9 A - F ] { 4 } - 4 [ 0 - 9 A - F ] { 3 } - [ 8 9 A B ] [ 0 - 9 A - F ] { 3 } - [ 0 - 9 A - F ] { 12 } $ / i) ;
61- } ) ;
64+ const data = await send ( 'pdf.render' , message ) ;
65+ expect ( data ) . toMatch ( / ^ [ 0 - 9 A - F ] { 8 } - [ 0 - 9 A - F ] { 4 } - 4 [ 0 - 9 A - F ] { 3 } - [ 8 9 A B ] [ 0 - 9 A - F ] { 3 } - [ 0 - 9 A - F ] { 12 } $ / i) ;
66+ } ) ;
67+
68+ it ( 'should render & upload document' , async ( ) => {
69+ const message = {
70+ template : 'font' ,
71+ context : { } ,
72+ meta : {
73+ meta : {
74+ name : 'font.pdf' ,
75+ } ,
76+ username : 'test' ,
77+ unlisted : true ,
78+ access : {
79+ setPublic : true ,
80+ } ,
81+ } ,
82+ } ;
83+
84+ const data = await send ( 'pdf.render' , message ) ;
85+ expect ( data ) . toMatch ( / ^ [ 0 - 9 A - F ] { 8 } - [ 0 - 9 A - F ] { 4 } - 4 [ 0 - 9 A - F ] { 3 } - [ 8 9 A B ] [ 0 - 9 A - F ] { 3 } - [ 0 - 9 A - F ] { 12 } $ / i) ;
6286 } ) ;
6387
64- afterAll ( ( ) => {
65- return this . service . close ( ) ;
88+ afterAll ( async ( ) => {
89+ await service . close ( ) ;
6690 } ) ;
6791} ) ;
0 commit comments