orator-conversion 1.0.2 → 1.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -640,6 +640,154 @@ suite
640
640
  }
641
641
  );
642
642
 
643
+ suite
644
+ (
645
+ 'Image Resize Endpoint',
646
+ () =>
647
+ {
648
+ test
649
+ (
650
+ 'should resize an image via the resize endpoint',
651
+ (fDone) =>
652
+ {
653
+ createTestJpegBuffer(
654
+ (pError, pJpegBuffer) =>
655
+ {
656
+ Expect(pError).to.equal(null);
657
+
658
+ createStartedHarness(null, null,
659
+ (pHarness) =>
660
+ {
661
+ postBinaryToEndpoint(pHarness.port, '/conversion/1.0/image/resize?Width=5&Height=5', pJpegBuffer,
662
+ (pPostError, pResponse, pBody) =>
663
+ {
664
+ Expect(pPostError).to.equal(null);
665
+ Expect(pResponse.statusCode).to.equal(200);
666
+ Expect(pBody).to.be.an.instanceOf(Buffer);
667
+ Expect(pBody.length).to.be.greaterThan(0);
668
+
669
+ libSharp(pBody).metadata().then(
670
+ (pMetadata) =>
671
+ {
672
+ Expect(pMetadata.width).to.equal(5);
673
+ Expect(pMetadata.height).to.equal(5);
674
+ pHarness.orator.stopService(fDone);
675
+ }).catch(
676
+ (pMetaError) =>
677
+ {
678
+ pHarness.orator.stopService(() => { fDone(pMetaError); });
679
+ });
680
+ });
681
+ });
682
+ });
683
+ }
684
+ );
685
+ }
686
+ );
687
+
688
+ suite
689
+ (
690
+ 'Image Rotate Endpoint',
691
+ () =>
692
+ {
693
+ test
694
+ (
695
+ 'should rotate an image 90 degrees via the rotate endpoint',
696
+ (fDone) =>
697
+ {
698
+ createTestJpegBuffer(
699
+ (pError, pJpegBuffer) =>
700
+ {
701
+ Expect(pError).to.equal(null);
702
+
703
+ createStartedHarness(null, null,
704
+ (pHarness) =>
705
+ {
706
+ postBinaryToEndpoint(pHarness.port, '/conversion/1.0/image/rotate/90', pJpegBuffer,
707
+ (pPostError, pResponse, pBody) =>
708
+ {
709
+ Expect(pPostError).to.equal(null);
710
+ Expect(pResponse.statusCode).to.equal(200);
711
+ Expect(pBody).to.be.an.instanceOf(Buffer);
712
+ Expect(pBody.length).to.be.greaterThan(0);
713
+
714
+ pHarness.orator.stopService(fDone);
715
+ });
716
+ });
717
+ });
718
+ }
719
+ );
720
+ }
721
+ );
722
+
723
+ suite
724
+ (
725
+ 'Image Convert Endpoint',
726
+ () =>
727
+ {
728
+ test
729
+ (
730
+ 'should convert a JPEG to PNG via the convert endpoint',
731
+ (fDone) =>
732
+ {
733
+ createTestJpegBuffer(
734
+ (pError, pJpegBuffer) =>
735
+ {
736
+ Expect(pError).to.equal(null);
737
+
738
+ createStartedHarness(null, null,
739
+ (pHarness) =>
740
+ {
741
+ postBinaryToEndpoint(pHarness.port, '/conversion/1.0/image/convert/png', pJpegBuffer,
742
+ (pPostError, pResponse, pBody) =>
743
+ {
744
+ Expect(pPostError).to.equal(null);
745
+ Expect(pResponse.statusCode).to.equal(200);
746
+ Expect(pResponse.headers['content-type']).to.equal('image/png');
747
+
748
+ // Verify PNG magic bytes
749
+ Expect(pBody[0]).to.equal(137);
750
+ Expect(pBody[1]).to.equal(80);
751
+ Expect(pBody[2]).to.equal(78);
752
+ Expect(pBody[3]).to.equal(71);
753
+
754
+ pHarness.orator.stopService(fDone);
755
+ });
756
+ });
757
+ });
758
+ }
759
+ );
760
+
761
+ test
762
+ (
763
+ 'should convert a JPEG to WebP via the convert endpoint',
764
+ (fDone) =>
765
+ {
766
+ createTestJpegBuffer(
767
+ (pError, pJpegBuffer) =>
768
+ {
769
+ Expect(pError).to.equal(null);
770
+
771
+ createStartedHarness(null, null,
772
+ (pHarness) =>
773
+ {
774
+ postBinaryToEndpoint(pHarness.port, '/conversion/1.0/image/convert/webp', pJpegBuffer,
775
+ (pPostError, pResponse, pBody) =>
776
+ {
777
+ Expect(pPostError).to.equal(null);
778
+ Expect(pResponse.statusCode).to.equal(200);
779
+ Expect(pResponse.headers['content-type']).to.equal('image/webp');
780
+ Expect(pBody.length).to.be.greaterThan(0);
781
+
782
+ pHarness.orator.stopService(fDone);
783
+ });
784
+ });
785
+ });
786
+ }
787
+ );
788
+ }
789
+ );
790
+
643
791
  suite
644
792
  (
645
793
  'Custom Converter',