@adobe/acc-js-sdk 1.0.5 → 1.0.8

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.
@@ -0,0 +1,64 @@
1
+ /*
2
+ Copyright 2020 Adobe. All rights reserved.
3
+ This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License. You may obtain a copy
5
+ of the License at http://www.apache.org/licenses/LICENSE-2.0
6
+
7
+ Unless required by applicable law or agreed to in writing, software distributed under
8
+ the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9
+ OF ANY KIND, either express or implied. See the License for the specific language
10
+ governing permissions and limitations under the License.
11
+ */
12
+
13
+ const sdk = require("../src");
14
+ const { DomUtil } = require("../src/domUtil");
15
+
16
+ describe('TestUtil', function() {
17
+
18
+ describe('Creating test schema', () => {
19
+ it ('Should create schema from string', () => {
20
+ const schema = sdk.TestUtil.newSchema(`
21
+ <schema namespace="nms" name="recipient">
22
+ <enumeration name="gender" basetype="byte">
23
+ <value name="unknown" label="None specified" value="0"/>
24
+ <value name="male" label="Male" value="1"/>
25
+ <value name="female" label="Female" value="2"/>
26
+ </enumeration>
27
+ <element name="recipient">
28
+ <attribute name="id" type="long"/>
29
+ <attribute name="email" type="string"/>
30
+ <attribute name="age" type="long"/>
31
+ <attribute name="gender" type="long" enum="nms:recipient:gender"/>
32
+ </element>
33
+ </schema>
34
+ `);
35
+ expect(schema.id).toBe("nms:recipient");
36
+ });
37
+
38
+ it ('Should create schema from XML', () => {
39
+ const xml = DomUtil.parse(`
40
+ <schema namespace="nms" name="recipient">
41
+ <enumeration name="gender" basetype="byte">
42
+ <value name="unknown" label="None specified" value="0"/>
43
+ <value name="male" label="Male" value="1"/>
44
+ <value name="female" label="Female" value="2"/>
45
+ </enumeration>
46
+ <element name="recipient">
47
+ <attribute name="id" type="long"/>
48
+ <attribute name="email" type="string"/>
49
+ <attribute name="age" type="long"/>
50
+ <attribute name="gender" type="long" enum="nms:recipient:gender"/>
51
+ </element>
52
+ </schema>
53
+ `);
54
+ // From DOM document
55
+ let schema = sdk.TestUtil.newSchema(xml);
56
+ expect(schema.id).toBe("nms:recipient");
57
+ // From DOM element
58
+ schema = sdk.TestUtil.newSchema(xml.documentElement);
59
+ expect(schema.id).toBe("nms:recipient");
60
+ });
61
+ });
62
+
63
+ });
64
+
package/test/util.test.js CHANGED
@@ -17,7 +17,8 @@ governing permissions and limitations under the License.
17
17
  *
18
18
  *********************************************************************************/
19
19
 
20
- const { Util, SafeStorage, Cache } = require('../src/util.js');
20
+ const { Util } = require('../src/util.js');
21
+ const { SafeStorage, Cache } = require('../src/cache.js');
21
22
 
22
23
 
23
24
  describe('Util', function() {
@@ -428,7 +428,9 @@ describe('XtkCaster', function() {
428
428
  const value = expected[0];
429
429
  const expectedResult = expected[1];
430
430
  it('Should return the value casted as a timestamp ("' + value + '")', function() {
431
- const actual = XtkCaster.asTimestamp(value);
431
+ let actual = XtkCaster.asTimestamp(value);
432
+ assert.myEquals(actual, expectedResult);
433
+ actual = XtkCaster.asDatetime(value);
432
434
  assert.myEquals(actual, expectedResult);
433
435
  });
434
436
  it('Should return the value casted as type datetime', function() {
@@ -696,14 +698,22 @@ describe('XtkCaster', function() {
696
698
  expect(XtkCaster._variantStorageAttribute(6)).toBe("stringValue");
697
699
  expect(XtkCaster._variantStorageAttribute("string")).toBe("stringValue");
698
700
  expect(XtkCaster._variantStorageAttribute("int64")).toBe("stringValue");
701
+ expect(XtkCaster._variantStorageAttribute("uuid")).toBe("stringValue");
699
702
  expect(XtkCaster._variantStorageAttribute(12)).toBe("memoValue");
700
703
  expect(XtkCaster._variantStorageAttribute(13)).toBe("memoValue");
701
704
  expect(XtkCaster._variantStorageAttribute("memo")).toBe("memoValue");
702
705
  expect(XtkCaster._variantStorageAttribute("CDATA")).toBe("memoValue");
706
+ expect(XtkCaster._variantStorageAttribute("blob")).toBe("memoValue");
707
+ expect(XtkCaster._variantStorageAttribute("html")).toBe("memoValue");
703
708
  expect(XtkCaster._variantStorageAttribute(1)).toBe("longValue");
704
709
  expect(XtkCaster._variantStorageAttribute(2)).toBe("longValue");
705
710
  expect(XtkCaster._variantStorageAttribute(3)).toBe("longValue");
706
711
  expect(XtkCaster._variantStorageAttribute(15)).toBe("longValue");
712
+ expect(XtkCaster._variantStorageAttribute("byte")).toBe("longValue");
713
+ expect(XtkCaster._variantStorageAttribute("short")).toBe("longValue");
714
+ expect(XtkCaster._variantStorageAttribute("long")).toBe("longValue");
715
+ expect(XtkCaster._variantStorageAttribute("int")).toBe("longValue");
716
+ expect(XtkCaster._variantStorageAttribute("boolean")).toBe("longValue");
707
717
  expect(XtkCaster._variantStorageAttribute(4)).toBe("doubleValue");
708
718
  expect(XtkCaster._variantStorageAttribute(5)).toBe("doubleValue");
709
719
  expect(XtkCaster._variantStorageAttribute("float")).toBe("doubleValue");
@@ -716,4 +726,212 @@ describe('XtkCaster', function() {
716
726
  expect(XtkCaster._variantStorageAttribute("date")).toBe("timeStampValue");
717
727
  expect(() => { XtkCaster._variantStorageAttribute(777); }).toThrow("Cannot get variant storage");
718
728
  });
729
+
730
+ describe("Array tests", () => {
731
+ it("Should return array", () => {
732
+ expect(XtkCaster.asArray(null)).toStrictEqual([]);
733
+ expect(XtkCaster.asArray(undefined)).toStrictEqual([]);
734
+ expect(XtkCaster.asArray(false)).toStrictEqual([false]);
735
+ expect(XtkCaster.asArray("Hello")).toStrictEqual(["Hello"]);
736
+ expect(XtkCaster.asArray([])).toStrictEqual([]);
737
+ expect(XtkCaster.asArray([null])).toStrictEqual([null]);
738
+ })
739
+
740
+ it("Should support arrays", () => {
741
+ expect(XtkCaster.as(null, "array")).toStrictEqual([]);
742
+ expect(XtkCaster.as(undefined, "array")).toStrictEqual([]);
743
+ expect(XtkCaster.as(false, "array")).toStrictEqual([false]);
744
+ expect(XtkCaster.as("Hello", "array")).toStrictEqual(["Hello"]);
745
+ expect(XtkCaster.as([], "array")).toStrictEqual([]);
746
+ expect(XtkCaster.as([null], "array")).toStrictEqual([null]);
747
+ });
748
+ });
749
+
750
+ describe("Timespan test", () => {
751
+ it("Should return timespan", () => {
752
+ expect(XtkCaster.asTimespan(null)).toStrictEqual(0);
753
+ expect(XtkCaster.asTimespan(undefined)).toStrictEqual(0);
754
+ expect(XtkCaster.asTimespan(false)).toStrictEqual(0);
755
+ expect(XtkCaster.asTimespan("Hello")).toStrictEqual(0);
756
+ expect(XtkCaster.asTimespan([])).toStrictEqual(0);
757
+ expect(XtkCaster.asTimespan([null])).toStrictEqual(0);
758
+ expect(XtkCaster.asTimespan(NaN)).toStrictEqual(0);
759
+ expect(XtkCaster.asTimespan(Number.POSITIVE_INFINITY)).toStrictEqual(0);
760
+ expect(XtkCaster.asTimespan(Number.NEGATIVE_INFINITY)).toStrictEqual(0);
761
+ expect(XtkCaster.asTimespan("86400")).toStrictEqual(86400);
762
+ expect(XtkCaster.asTimespan(86400)).toStrictEqual(86400);
763
+ })
764
+
765
+ it("As should support 'timspan'", () => {
766
+ expect(XtkCaster.as(null, "timespan")).toStrictEqual(0);
767
+ expect(XtkCaster.as(undefined, "timespan")).toStrictEqual(0);
768
+ expect(XtkCaster.as(false, "timespan")).toStrictEqual(0);
769
+ expect(XtkCaster.as("Hello", "timespan")).toStrictEqual(0);
770
+ expect(XtkCaster.as([], "timespan")).toStrictEqual(0);
771
+ expect(XtkCaster.as([null], "timespan")).toStrictEqual(0);
772
+ expect(XtkCaster.as("86400", "timespan")).toStrictEqual(86400);
773
+ expect(XtkCaster.as(86400, "timespan")).toStrictEqual(86400);
774
+ });
775
+
776
+ it("As should support type 14", () => {
777
+ expect(XtkCaster.as(null, 14)).toStrictEqual(0);
778
+ expect(XtkCaster.as(undefined, 14)).toStrictEqual(0);
779
+ expect(XtkCaster.as(false, 14)).toStrictEqual(0);
780
+ expect(XtkCaster.as("Hello", 14)).toStrictEqual(0);
781
+ expect(XtkCaster.as([], 14)).toStrictEqual(0);
782
+ expect(XtkCaster.as([null], 14)).toStrictEqual(0);
783
+ expect(XtkCaster.as("86400", 14)).toStrictEqual(86400);
784
+ expect(XtkCaster.as(86400, 14)).toStrictEqual(86400);
785
+ });
786
+ })
787
+
788
+ describe("Other string types", () => {
789
+ it("Type 'html'", () => {
790
+ expect(XtkCaster.as(null, "html")).toStrictEqual("");
791
+ expect(XtkCaster.as(undefined, "html")).toStrictEqual("");
792
+ expect(XtkCaster.as("Hello", "html")).toStrictEqual("Hello");
793
+ expect(XtkCaster.as("0", "html")).toStrictEqual("0");
794
+ });
795
+
796
+ it("Type 'uuid'", () => {
797
+ expect(XtkCaster.as(null, "uuid")).toStrictEqual("");
798
+ expect(XtkCaster.as(undefined, "uuid")).toStrictEqual("");
799
+ expect(XtkCaster.as("Hello", "uuid")).toStrictEqual("Hello");
800
+ expect(XtkCaster.as("0", "uuid")).toStrictEqual("0");
801
+ });
802
+
803
+ it("Type 'blob'", () => {
804
+ expect(XtkCaster.as(null, "blob")).toStrictEqual("");
805
+ expect(XtkCaster.as(undefined, "blob")).toStrictEqual("");
806
+ expect(XtkCaster.as("Hello", "blob")).toStrictEqual("Hello");
807
+ expect(XtkCaster.as("0", "blob")).toStrictEqual("0");
808
+ });
809
+
810
+ it("Type 'int'", () => {
811
+ expect(XtkCaster.as(null, "int")).toStrictEqual(0);
812
+ expect(XtkCaster.as(undefined, "int")).toStrictEqual(0);
813
+ expect(XtkCaster.as("42", "int")).toStrictEqual(42);
814
+ expect(XtkCaster.as("0", "int")).toStrictEqual(0);
815
+ });
816
+ })
817
+
818
+ it("Should check time type", () => {
819
+ expect(XtkCaster.isTimeType(null)).toBe(false);
820
+ expect(XtkCaster.isTimeType(undefined)).toBe(false);
821
+ expect(XtkCaster.isTimeType(0)).toBe(false);
822
+ expect(XtkCaster.isTimeType("")).toBe(false);
823
+ expect(XtkCaster.isTimeType(6)).toBe(false);
824
+ expect(XtkCaster.isTimeType("string")).toBe(false);
825
+ expect(XtkCaster.isTimeType("int64")).toBe(false);
826
+ expect(XtkCaster.isTimeType("uuid")).toBe(false);
827
+ expect(XtkCaster.isTimeType(12)).toBe(false);
828
+ expect(XtkCaster.isTimeType(13)).toBe(false);
829
+ expect(XtkCaster.isTimeType("memo")).toBe(false);
830
+ expect(XtkCaster.isTimeType("CDATA")).toBe(false);
831
+ expect(XtkCaster.isTimeType("blob")).toBe(false);
832
+ expect(XtkCaster.isTimeType("html")).toBe(false);
833
+ expect(XtkCaster.isTimeType(1)).toBe(false);
834
+ expect(XtkCaster.isTimeType(2)).toBe(false);
835
+ expect(XtkCaster.isTimeType(3)).toBe(false);
836
+ expect(XtkCaster.isTimeType(15)).toBe(false);
837
+ expect(XtkCaster.isTimeType("byte")).toBe(false);
838
+ expect(XtkCaster.isTimeType("short")).toBe(false);
839
+ expect(XtkCaster.isTimeType("long")).toBe(false);
840
+ expect(XtkCaster.isTimeType("int")).toBe(false);
841
+ expect(XtkCaster.isTimeType("boolean")).toBe(false);
842
+ expect(XtkCaster.isTimeType(4)).toBe(false);
843
+ expect(XtkCaster.isTimeType(5)).toBe(false);
844
+ expect(XtkCaster.isTimeType("float")).toBe(false);
845
+ expect(XtkCaster.isTimeType("double")).toBe(false);
846
+ expect(XtkCaster.isTimeType(7)).toBe(true);
847
+ expect(XtkCaster.isTimeType(10)).toBe(true);
848
+ expect(XtkCaster.isTimeType("datetime")).toBe(true);
849
+ expect(XtkCaster.isTimeType("timestamp")).toBe(true);
850
+ expect(XtkCaster.isTimeType("datetimetz")).toBe(true);
851
+ expect(XtkCaster.isTimeType("datetimenotz")).toBe(true);
852
+ expect(XtkCaster.isTimeType("date")).toBe(true);
853
+ expect(XtkCaster.isTimeType(14)).toBe(true);
854
+ expect(XtkCaster.isTimeType("time")).toBe(true);
855
+ expect(XtkCaster.isTimeType("timespan")).toBe(true);
856
+ });
857
+
858
+ it("Should check string type", () => {
859
+ expect(XtkCaster.isStringType(null)).toBe(false);
860
+ expect(XtkCaster.isStringType(undefined)).toBe(false);
861
+ expect(XtkCaster.isStringType(0)).toBe(false);
862
+ expect(XtkCaster.isStringType("")).toBe(false);
863
+ expect(XtkCaster.isStringType(6)).toBe(true);
864
+ expect(XtkCaster.isStringType("string")).toBe(true);
865
+ expect(XtkCaster.isStringType("int64")).toBe(false);
866
+ expect(XtkCaster.isStringType("uuid")).toBe(false);
867
+ expect(XtkCaster.isStringType(12)).toBe(true);
868
+ expect(XtkCaster.isStringType(13)).toBe(true);
869
+ expect(XtkCaster.isStringType("memo")).toBe(true);
870
+ expect(XtkCaster.isStringType("CDATA")).toBe(true);
871
+ expect(XtkCaster.isStringType("blob")).toBe(true);
872
+ expect(XtkCaster.isStringType("html")).toBe(true);
873
+ expect(XtkCaster.isStringType(1)).toBe(false);
874
+ expect(XtkCaster.isStringType(2)).toBe(false);
875
+ expect(XtkCaster.isStringType(3)).toBe(false);
876
+ expect(XtkCaster.isStringType(15)).toBe(false);
877
+ expect(XtkCaster.isStringType("byte")).toBe(false);
878
+ expect(XtkCaster.isStringType("short")).toBe(false);
879
+ expect(XtkCaster.isStringType("long")).toBe(false);
880
+ expect(XtkCaster.isStringType("int")).toBe(false);
881
+ expect(XtkCaster.isStringType("boolean")).toBe(false);
882
+ expect(XtkCaster.isStringType(4)).toBe(false);
883
+ expect(XtkCaster.isStringType(5)).toBe(false);
884
+ expect(XtkCaster.isStringType("float")).toBe(false);
885
+ expect(XtkCaster.isStringType("double")).toBe(false);
886
+ expect(XtkCaster.isStringType(7)).toBe(false);
887
+ expect(XtkCaster.isStringType(10)).toBe(false);
888
+ expect(XtkCaster.isStringType("datetime")).toBe(false);
889
+ expect(XtkCaster.isStringType("timestamp")).toBe(false);
890
+ expect(XtkCaster.isStringType("datetimetz")).toBe(false);
891
+ expect(XtkCaster.isStringType("datetimenotz")).toBe(false);
892
+ expect(XtkCaster.isStringType("date")).toBe(false);
893
+ expect(XtkCaster.isStringType(14)).toBe(false);
894
+ expect(XtkCaster.isStringType("time")).toBe(false);
895
+ expect(XtkCaster.isStringType("timespan")).toBe(false);
896
+ });
897
+
898
+ it("Should check number type", () => {
899
+ expect(XtkCaster.isNumericType(null)).toBe(false);
900
+ expect(XtkCaster.isNumericType(undefined)).toBe(false);
901
+ expect(XtkCaster.isNumericType(0)).toBe(false);
902
+ expect(XtkCaster.isNumericType("")).toBe(false);
903
+ expect(XtkCaster.isNumericType(6)).toBe(false);
904
+ expect(XtkCaster.isNumericType("string")).toBe(false);
905
+ expect(XtkCaster.isNumericType("int64")).toBe(false);
906
+ expect(XtkCaster.isNumericType("uuid")).toBe(false);
907
+ expect(XtkCaster.isNumericType(12)).toBe(false);
908
+ expect(XtkCaster.isNumericType(13)).toBe(false);
909
+ expect(XtkCaster.isNumericType("memo")).toBe(false);
910
+ expect(XtkCaster.isNumericType("CDATA")).toBe(false);
911
+ expect(XtkCaster.isNumericType("blob")).toBe(false);
912
+ expect(XtkCaster.isNumericType("html")).toBe(false);
913
+ expect(XtkCaster.isNumericType(1)).toBe(true);
914
+ expect(XtkCaster.isNumericType(2)).toBe(true);
915
+ expect(XtkCaster.isNumericType(3)).toBe(true);
916
+ expect(XtkCaster.isNumericType(15)).toBe(false);
917
+ expect(XtkCaster.isNumericType("byte")).toBe(true);
918
+ expect(XtkCaster.isNumericType("short")).toBe(true);
919
+ expect(XtkCaster.isNumericType("long")).toBe(true);
920
+ expect(XtkCaster.isNumericType("int")).toBe(true);
921
+ expect(XtkCaster.isNumericType("boolean")).toBe(false);
922
+ expect(XtkCaster.isNumericType(4)).toBe(true);
923
+ expect(XtkCaster.isNumericType(5)).toBe(true);
924
+ expect(XtkCaster.isNumericType("float")).toBe(true);
925
+ expect(XtkCaster.isNumericType("double")).toBe(true);
926
+ expect(XtkCaster.isNumericType(7)).toBe(false);
927
+ expect(XtkCaster.isNumericType(10)).toBe(false);
928
+ expect(XtkCaster.isNumericType("datetime")).toBe(false);
929
+ expect(XtkCaster.isNumericType("timestamp")).toBe(false);
930
+ expect(XtkCaster.isNumericType("datetimetz")).toBe(false);
931
+ expect(XtkCaster.isNumericType("datetimenotz")).toBe(false);
932
+ expect(XtkCaster.isNumericType("date")).toBe(false);
933
+ expect(XtkCaster.isNumericType(14)).toBe(true);
934
+ expect(XtkCaster.isNumericType("time")).toBe(false);
935
+ expect(XtkCaster.isNumericType("timespan")).toBe(true);
936
+ });
719
937
  });