docusaurus-plugin-generate-schema-docs 1.8.3 → 1.8.5
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.
- package/README.md +12 -0
- package/__tests__/__fixtures__/validateSchemas/main-schema-with-not-allof.json +11 -0
- package/__tests__/__fixtures__/validateSchemas/schema-with-not-anyof-multi.json +12 -0
- package/__tests__/__fixtures__/validateSchemas/schema-with-not-anyof.json +30 -0
- package/__tests__/__fixtures__/validateSchemas/schema-with-not-edge-cases.json +24 -0
- package/__tests__/__fixtures__/validateSchemas/schema-with-not-non-object.json +15 -0
- package/__tests__/__snapshots__/generateEventDocs.anchor.test.js.snap +6 -0
- package/__tests__/__snapshots__/generateEventDocs.nested.test.js.snap +6 -0
- package/__tests__/__snapshots__/generateEventDocs.test.js.snap +15 -0
- package/__tests__/__snapshots__/generateEventDocs.versioned.test.js.snap +6 -0
- package/__tests__/components/PropertiesTable.test.js +66 -0
- package/__tests__/components/PropertyRow.test.js +85 -4
- package/__tests__/components/SchemaJsonViewer.test.js +118 -0
- package/__tests__/generateEventDocs.anchor.test.js +1 -1
- package/__tests__/generateEventDocs.nested.test.js +1 -1
- package/__tests__/generateEventDocs.partials.test.js +1 -1
- package/__tests__/generateEventDocs.test.js +506 -1
- package/__tests__/generateEventDocs.versioned.test.js +1 -1
- package/__tests__/helpers/buildExampleFromSchema.test.js +240 -0
- package/__tests__/helpers/constraintSchemaPaths.test.js +208 -0
- package/__tests__/helpers/continuingLinesStyle.test.js +492 -0
- package/__tests__/helpers/example-helper.test.js +12 -0
- package/__tests__/helpers/exampleModel.test.js +209 -0
- package/__tests__/helpers/file-system.test.js +73 -1
- package/__tests__/helpers/getConstraints.test.js +43 -0
- package/__tests__/helpers/mergeSchema.test.js +94 -0
- package/__tests__/helpers/processSchema.test.js +309 -1
- package/__tests__/helpers/schema-doc-template.test.js +54 -0
- package/__tests__/helpers/schema-processing.test.js +122 -2
- package/__tests__/helpers/schemaToExamples.test.js +1007 -0
- package/__tests__/helpers/schemaToTableData.mutations.test.js +970 -0
- package/__tests__/helpers/schemaToTableData.test.js +157 -0
- package/__tests__/helpers/schemaTraversal.test.js +110 -0
- package/__tests__/helpers/snippetTargets.test.js +432 -0
- package/__tests__/helpers/trackingTargets.test.js +319 -0
- package/__tests__/helpers/validator.test.js +385 -1
- package/__tests__/index.test.js +436 -0
- package/__tests__/syncGtm.test.js +366 -6
- package/__tests__/update-schema-ids.test.js +70 -1
- package/__tests__/validateSchemas-integration.test.js +2 -2
- package/__tests__/validateSchemas.test.js +192 -1
- package/components/PropertiesTable.js +32 -2
- package/components/PropertyRow.js +29 -2
- package/components/SchemaJsonViewer.js +234 -131
- package/components/SchemaRows.css +40 -0
- package/components/SchemaViewer.js +11 -2
- package/generateEventDocs.js +21 -1
- package/helpers/constraintSchemaPaths.js +10 -14
- package/helpers/example-helper.js +2 -2
- package/helpers/getConstraints.js +20 -0
- package/helpers/processSchema.js +32 -1
- package/helpers/schema-doc-template.js +4 -0
- package/helpers/schemaToExamples.js +29 -35
- package/helpers/schemaToTableData.js +538 -492
- package/helpers/schemaTraversal.cjs +148 -0
- package/helpers/trackingTargets.js +26 -3
- package/helpers/validator.js +18 -4
- package/index.js +1 -2
- package/package.json +1 -1
- package/scripts/sync-gtm.js +65 -34
- package/test-data/payloadContracts.js +35 -0
- package/validateSchemas.js +1 -1
|
@@ -684,6 +684,264 @@ describe('snippetTargets', () => {
|
|
|
684
684
|
expect(objcSnippet).toContain('kFIRParameterCoupon: @"WELCOME10"');
|
|
685
685
|
});
|
|
686
686
|
|
|
687
|
+
it('emits null user property value for kotlin snippet', () => {
|
|
688
|
+
const snippet = generateSnippetForTarget({
|
|
689
|
+
targetId: 'android-firebase-kotlin-sdk',
|
|
690
|
+
example: {
|
|
691
|
+
event: 'login',
|
|
692
|
+
user_properties: { custom_prop: null },
|
|
693
|
+
},
|
|
694
|
+
schema: { properties: {} },
|
|
695
|
+
});
|
|
696
|
+
expect(snippet).toContain(
|
|
697
|
+
'firebaseAnalytics.setUserProperty("custom_prop", null)',
|
|
698
|
+
);
|
|
699
|
+
});
|
|
700
|
+
|
|
701
|
+
it('emits null user property value for java snippet', () => {
|
|
702
|
+
const snippet = generateSnippetForTarget({
|
|
703
|
+
targetId: 'android-firebase-java-sdk',
|
|
704
|
+
example: {
|
|
705
|
+
event: 'login',
|
|
706
|
+
user_properties: { custom_prop: null },
|
|
707
|
+
},
|
|
708
|
+
schema: { properties: {} },
|
|
709
|
+
});
|
|
710
|
+
expect(snippet).toContain(
|
|
711
|
+
'mFirebaseAnalytics.setUserProperty("custom_prop", null);',
|
|
712
|
+
);
|
|
713
|
+
});
|
|
714
|
+
|
|
715
|
+
it('emits nil user property value for swift snippet', () => {
|
|
716
|
+
const snippet = generateSnippetForTarget({
|
|
717
|
+
targetId: 'ios-firebase-swift-sdk',
|
|
718
|
+
example: {
|
|
719
|
+
event: 'login',
|
|
720
|
+
user_properties: { custom_prop: null },
|
|
721
|
+
},
|
|
722
|
+
schema: { properties: {} },
|
|
723
|
+
});
|
|
724
|
+
expect(snippet).toContain(
|
|
725
|
+
'Analytics.setUserProperty(nil, forName: "custom_prop")',
|
|
726
|
+
);
|
|
727
|
+
});
|
|
728
|
+
|
|
729
|
+
it('emits nil log call with parameters:nil for swift when no params', () => {
|
|
730
|
+
const snippet = generateSnippetForTarget({
|
|
731
|
+
targetId: 'ios-firebase-swift-sdk',
|
|
732
|
+
example: {
|
|
733
|
+
event: 'login',
|
|
734
|
+
user_properties: { plan: 'free' },
|
|
735
|
+
},
|
|
736
|
+
schema: { properties: {} },
|
|
737
|
+
});
|
|
738
|
+
expect(snippet).toContain(
|
|
739
|
+
'Analytics.logEvent(AnalyticsEventLogin, parameters: nil)',
|
|
740
|
+
);
|
|
741
|
+
});
|
|
742
|
+
|
|
743
|
+
it('emits parameters:nil for objc when no params', () => {
|
|
744
|
+
const snippet = generateSnippetForTarget({
|
|
745
|
+
targetId: 'ios-firebase-objc-sdk',
|
|
746
|
+
example: { event: 'login' },
|
|
747
|
+
schema: { properties: {} },
|
|
748
|
+
});
|
|
749
|
+
expect(snippet).toContain(
|
|
750
|
+
'[FIRAnalytics logEventWithName:kFIREventLogin parameters:nil];',
|
|
751
|
+
);
|
|
752
|
+
});
|
|
753
|
+
|
|
754
|
+
it('emits @"string" user property for objc with non-predefined key', () => {
|
|
755
|
+
const snippet = generateSnippetForTarget({
|
|
756
|
+
targetId: 'ios-firebase-objc-sdk',
|
|
757
|
+
example: {
|
|
758
|
+
event: 'login',
|
|
759
|
+
user_properties: { custom_user_prop: 'value' },
|
|
760
|
+
},
|
|
761
|
+
schema: { properties: {} },
|
|
762
|
+
});
|
|
763
|
+
expect(snippet).toContain(
|
|
764
|
+
'[FIRAnalytics setUserPropertyString:@"value" forName:@"custom_user_prop"];',
|
|
765
|
+
);
|
|
766
|
+
});
|
|
767
|
+
|
|
768
|
+
it('coerces number and boolean user properties to strings', () => {
|
|
769
|
+
const kotlinSnippet = generateSnippetForTarget({
|
|
770
|
+
targetId: 'android-firebase-kotlin-sdk',
|
|
771
|
+
example: {
|
|
772
|
+
event: 'login',
|
|
773
|
+
user_properties: { count: 42, active: true },
|
|
774
|
+
},
|
|
775
|
+
schema: { properties: {} },
|
|
776
|
+
});
|
|
777
|
+
const javaSnippet = generateSnippetForTarget({
|
|
778
|
+
targetId: 'android-firebase-java-sdk',
|
|
779
|
+
example: {
|
|
780
|
+
event: 'login',
|
|
781
|
+
user_properties: { count: 42, active: false },
|
|
782
|
+
},
|
|
783
|
+
schema: { properties: {} },
|
|
784
|
+
});
|
|
785
|
+
|
|
786
|
+
expect(kotlinSnippet).toContain(
|
|
787
|
+
'firebaseAnalytics.setUserProperty("count", "42")',
|
|
788
|
+
);
|
|
789
|
+
expect(kotlinSnippet).toContain(
|
|
790
|
+
'firebaseAnalytics.setUserProperty("active", "true")',
|
|
791
|
+
);
|
|
792
|
+
expect(javaSnippet).toContain(
|
|
793
|
+
'mFirebaseAnalytics.setUserProperty("count", "42");',
|
|
794
|
+
);
|
|
795
|
+
expect(javaSnippet).toContain(
|
|
796
|
+
'mFirebaseAnalytics.setUserProperty("active", "false");',
|
|
797
|
+
);
|
|
798
|
+
});
|
|
799
|
+
|
|
800
|
+
it('throws when user property value is an unsupported type (object)', () => {
|
|
801
|
+
expect(() =>
|
|
802
|
+
generateSnippetForTarget({
|
|
803
|
+
targetId: 'android-firebase-kotlin-sdk',
|
|
804
|
+
example: {
|
|
805
|
+
event: 'login',
|
|
806
|
+
user_properties: { nested: { a: 1 } },
|
|
807
|
+
},
|
|
808
|
+
schema: { properties: {} },
|
|
809
|
+
}),
|
|
810
|
+
).toThrow('user_properties.nested');
|
|
811
|
+
});
|
|
812
|
+
|
|
813
|
+
it('throws when items array contains non-object items', () => {
|
|
814
|
+
expect(() =>
|
|
815
|
+
generateSnippetForTarget({
|
|
816
|
+
targetId: 'android-firebase-kotlin-sdk',
|
|
817
|
+
example: {
|
|
818
|
+
event: 'purchase',
|
|
819
|
+
items: ['invalid-item'],
|
|
820
|
+
},
|
|
821
|
+
schema: { properties: {} },
|
|
822
|
+
}),
|
|
823
|
+
).toThrow('non-empty array of objects');
|
|
824
|
+
});
|
|
825
|
+
|
|
826
|
+
it('throws when items is an empty array', () => {
|
|
827
|
+
expect(() =>
|
|
828
|
+
generateSnippetForTarget({
|
|
829
|
+
targetId: 'android-firebase-kotlin-sdk',
|
|
830
|
+
example: {
|
|
831
|
+
event: 'purchase',
|
|
832
|
+
items: [],
|
|
833
|
+
},
|
|
834
|
+
schema: { properties: {} },
|
|
835
|
+
}),
|
|
836
|
+
).toThrow('non-empty array of objects');
|
|
837
|
+
});
|
|
838
|
+
|
|
839
|
+
it('handles items with boolean values in kotlin bundles', () => {
|
|
840
|
+
const snippet = generateSnippetForTarget({
|
|
841
|
+
targetId: 'android-firebase-kotlin-sdk',
|
|
842
|
+
example: {
|
|
843
|
+
event: 'purchase',
|
|
844
|
+
items: [{ item_id: 'sku-1', is_featured: true, custom_score: 5.5 }],
|
|
845
|
+
},
|
|
846
|
+
schema: { properties: {} },
|
|
847
|
+
});
|
|
848
|
+
expect(snippet).toContain(
|
|
849
|
+
'putString(FirebaseAnalytics.Param.ITEM_ID, "sku-1")',
|
|
850
|
+
);
|
|
851
|
+
expect(snippet).toContain('putLong("is_featured", 1L)');
|
|
852
|
+
expect(snippet).toContain('putDouble("custom_score", 5.5)');
|
|
853
|
+
});
|
|
854
|
+
|
|
855
|
+
it('handles items with boolean values in java bundles', () => {
|
|
856
|
+
const snippet = generateSnippetForTarget({
|
|
857
|
+
targetId: 'android-firebase-java-sdk',
|
|
858
|
+
example: {
|
|
859
|
+
event: 'purchase',
|
|
860
|
+
items: [{ item_id: 'sku-1', is_sale: false, custom_price: 2.5 }],
|
|
861
|
+
},
|
|
862
|
+
schema: { properties: {} },
|
|
863
|
+
});
|
|
864
|
+
expect(snippet).toContain(
|
|
865
|
+
'item1.putString(FirebaseAnalytics.Param.ITEM_ID, "sku-1");',
|
|
866
|
+
);
|
|
867
|
+
expect(snippet).toContain('item1.putLong("is_sale", 0L);');
|
|
868
|
+
expect(snippet).toContain('item1.putDouble("custom_price", 2.5);');
|
|
869
|
+
});
|
|
870
|
+
|
|
871
|
+
it('handles items with boolean values in swift item dicts', () => {
|
|
872
|
+
const snippet = generateSnippetForTarget({
|
|
873
|
+
targetId: 'ios-firebase-swift-sdk',
|
|
874
|
+
example: {
|
|
875
|
+
event: 'purchase',
|
|
876
|
+
items: [
|
|
877
|
+
{ item_id: 'sku-1', flag: true, price: 9.99 },
|
|
878
|
+
{ item_id: 'sku-2', flag: false },
|
|
879
|
+
],
|
|
880
|
+
},
|
|
881
|
+
schema: { properties: {} },
|
|
882
|
+
});
|
|
883
|
+
expect(snippet).toContain('AnalyticsParameterItemID: "sku-1"');
|
|
884
|
+
expect(snippet).toContain('"flag": 1,');
|
|
885
|
+
expect(snippet).toContain('AnalyticsParameterPrice: 9.99');
|
|
886
|
+
expect(snippet).toContain('AnalyticsParameterItemID: "sku-2"');
|
|
887
|
+
expect(snippet).toContain('"flag": 0');
|
|
888
|
+
});
|
|
889
|
+
|
|
890
|
+
it('handles items with boolean values in objc item dicts', () => {
|
|
891
|
+
const snippet = generateSnippetForTarget({
|
|
892
|
+
targetId: 'ios-firebase-objc-sdk',
|
|
893
|
+
example: {
|
|
894
|
+
event: 'purchase',
|
|
895
|
+
items: [
|
|
896
|
+
{ item_id: 'sku-1', flag: true, price: 9.99 },
|
|
897
|
+
{ item_id: 'sku-2' },
|
|
898
|
+
],
|
|
899
|
+
},
|
|
900
|
+
schema: { properties: {} },
|
|
901
|
+
});
|
|
902
|
+
expect(snippet).toContain('kFIRParameterItemID: @"sku-1"');
|
|
903
|
+
expect(snippet).toContain('@"flag": @(1),');
|
|
904
|
+
expect(snippet).toContain('kFIRParameterPrice: @(9.99)');
|
|
905
|
+
expect(snippet).toContain('kFIRParameterItemID: @"sku-2"');
|
|
906
|
+
});
|
|
907
|
+
|
|
908
|
+
it('throws when item value in bundle is an unsupported type (nested object)', () => {
|
|
909
|
+
expect(() =>
|
|
910
|
+
generateSnippetForTarget({
|
|
911
|
+
targetId: 'android-firebase-kotlin-sdk',
|
|
912
|
+
example: {
|
|
913
|
+
event: 'purchase',
|
|
914
|
+
items: [{ item_id: 'sku-1', metadata: { nested: true } }],
|
|
915
|
+
},
|
|
916
|
+
schema: { properties: {} },
|
|
917
|
+
}),
|
|
918
|
+
).toThrow('items[0].metadata');
|
|
919
|
+
});
|
|
920
|
+
|
|
921
|
+
it('includes error type label "null" and "array" in shape error message', () => {
|
|
922
|
+
expect(() =>
|
|
923
|
+
generateSnippetForTarget({
|
|
924
|
+
targetId: 'android-firebase-kotlin-sdk',
|
|
925
|
+
example: {
|
|
926
|
+
event: 'purchase',
|
|
927
|
+
items: [{ item_id: 'sku-1', bad: null }],
|
|
928
|
+
},
|
|
929
|
+
schema: { properties: {} },
|
|
930
|
+
}),
|
|
931
|
+
).toThrow('null');
|
|
932
|
+
|
|
933
|
+
expect(() =>
|
|
934
|
+
generateSnippetForTarget({
|
|
935
|
+
targetId: 'android-firebase-kotlin-sdk',
|
|
936
|
+
example: {
|
|
937
|
+
event: 'purchase',
|
|
938
|
+
items: [{ item_id: 'sku-1', bad: [1, 2] }],
|
|
939
|
+
},
|
|
940
|
+
schema: { properties: {} },
|
|
941
|
+
}),
|
|
942
|
+
).toThrow('array');
|
|
943
|
+
});
|
|
944
|
+
|
|
687
945
|
it('maps additional Firebase commerce constants present in reference docs', () => {
|
|
688
946
|
const kotlinSnippet = generateSnippetForTarget({
|
|
689
947
|
targetId: 'android-firebase-kotlin-sdk',
|
|
@@ -741,4 +999,178 @@ describe('snippetTargets', () => {
|
|
|
741
999
|
expect(swiftSnippet).toContain('AnalyticsParameterFreeTrial: 0');
|
|
742
1000
|
expect(swiftSnippet).toContain('AnalyticsParameterPriceIsDiscounted: 1');
|
|
743
1001
|
});
|
|
1002
|
+
|
|
1003
|
+
it('snippet does not begin with stray content for kotlin (no items, no user_properties)', () => {
|
|
1004
|
+
const snippet = generateSnippetForTarget({
|
|
1005
|
+
targetId: 'android-firebase-kotlin-sdk',
|
|
1006
|
+
example: { event: 'login', method: 'email' },
|
|
1007
|
+
schema: { properties: {} },
|
|
1008
|
+
});
|
|
1009
|
+
expect(snippet.startsWith('firebaseAnalytics.logEvent(')).toBe(true);
|
|
1010
|
+
});
|
|
1011
|
+
|
|
1012
|
+
it('snippet does not begin with stray content for java (no items, no user_properties)', () => {
|
|
1013
|
+
const snippet = generateSnippetForTarget({
|
|
1014
|
+
targetId: 'android-firebase-java-sdk',
|
|
1015
|
+
example: { event: 'login', method: 'email' },
|
|
1016
|
+
schema: { properties: {} },
|
|
1017
|
+
});
|
|
1018
|
+
expect(snippet.startsWith('Bundle eventParams = new Bundle();')).toBe(true);
|
|
1019
|
+
});
|
|
1020
|
+
|
|
1021
|
+
it('handles user_properties: null gracefully (returns no user property lines)', () => {
|
|
1022
|
+
const snippet = generateSnippetForTarget({
|
|
1023
|
+
targetId: 'android-firebase-kotlin-sdk',
|
|
1024
|
+
example: { event: 'login', user_properties: null },
|
|
1025
|
+
schema: { properties: {} },
|
|
1026
|
+
});
|
|
1027
|
+
expect(snippet).not.toContain('setUserProperty');
|
|
1028
|
+
expect(snippet).toContain(
|
|
1029
|
+
'firebaseAnalytics.logEvent(FirebaseAnalytics.Event.LOGIN)',
|
|
1030
|
+
);
|
|
1031
|
+
});
|
|
1032
|
+
|
|
1033
|
+
it('skips event and $schema keys in firebase param entries', () => {
|
|
1034
|
+
const kotlinSnippet = generateSnippetForTarget({
|
|
1035
|
+
targetId: 'android-firebase-kotlin-sdk',
|
|
1036
|
+
example: {
|
|
1037
|
+
event: 'custom_event',
|
|
1038
|
+
$schema: 'https://example.com/schema.json',
|
|
1039
|
+
custom_method: 'email',
|
|
1040
|
+
},
|
|
1041
|
+
schema: { properties: {} },
|
|
1042
|
+
});
|
|
1043
|
+
expect(kotlinSnippet).not.toContain('"event"');
|
|
1044
|
+
expect(kotlinSnippet).not.toContain('"$schema"');
|
|
1045
|
+
expect(kotlinSnippet).toContain('param("custom_method", "email")');
|
|
1046
|
+
});
|
|
1047
|
+
|
|
1048
|
+
it('kotlin snippet with items starts with item bundles, not stray content', () => {
|
|
1049
|
+
const snippet = generateSnippetForTarget({
|
|
1050
|
+
targetId: 'android-firebase-kotlin-sdk',
|
|
1051
|
+
example: {
|
|
1052
|
+
event: 'purchase',
|
|
1053
|
+
items: [{ item_id: 'sku-1' }],
|
|
1054
|
+
},
|
|
1055
|
+
schema: { properties: {} },
|
|
1056
|
+
});
|
|
1057
|
+
expect(snippet.startsWith('val item1 = Bundle().apply {')).toBe(true);
|
|
1058
|
+
});
|
|
1059
|
+
|
|
1060
|
+
it('java snippet with items starts with item bundles, not stray content', () => {
|
|
1061
|
+
const snippet = generateSnippetForTarget({
|
|
1062
|
+
targetId: 'android-firebase-java-sdk',
|
|
1063
|
+
example: {
|
|
1064
|
+
event: 'purchase',
|
|
1065
|
+
items: [{ item_id: 'sku-1' }],
|
|
1066
|
+
},
|
|
1067
|
+
schema: { properties: {} },
|
|
1068
|
+
});
|
|
1069
|
+
expect(snippet.startsWith('Bundle item1 = new Bundle();')).toBe(true);
|
|
1070
|
+
});
|
|
1071
|
+
|
|
1072
|
+
it('swift snippet with items starts with item dicts, not stray content', () => {
|
|
1073
|
+
const snippet = generateSnippetForTarget({
|
|
1074
|
+
targetId: 'ios-firebase-swift-sdk',
|
|
1075
|
+
example: {
|
|
1076
|
+
event: 'purchase',
|
|
1077
|
+
items: [{ item_id: 'sku-1' }],
|
|
1078
|
+
},
|
|
1079
|
+
schema: { properties: {} },
|
|
1080
|
+
});
|
|
1081
|
+
expect(snippet.startsWith('var item1: [String: Any] = [')).toBe(true);
|
|
1082
|
+
});
|
|
1083
|
+
|
|
1084
|
+
it('objc snippet with items starts with item dicts, not stray content', () => {
|
|
1085
|
+
const snippet = generateSnippetForTarget({
|
|
1086
|
+
targetId: 'ios-firebase-objc-sdk',
|
|
1087
|
+
example: {
|
|
1088
|
+
event: 'purchase',
|
|
1089
|
+
items: [{ item_id: 'sku-1' }],
|
|
1090
|
+
},
|
|
1091
|
+
schema: { properties: {} },
|
|
1092
|
+
});
|
|
1093
|
+
expect(snippet.startsWith('NSMutableDictionary *item1 = [@{')).toBe(true);
|
|
1094
|
+
});
|
|
1095
|
+
|
|
1096
|
+
// L839: generateSnippetForTarget default-arg — omit targetId to trigger default
|
|
1097
|
+
it('uses default targetId when none is provided', () => {
|
|
1098
|
+
const snippet = generateSnippetForTarget({
|
|
1099
|
+
example: { event: 'test_event' },
|
|
1100
|
+
schema: { properties: {} },
|
|
1101
|
+
});
|
|
1102
|
+
|
|
1103
|
+
expect(snippet).toContain('window.dataLayer.push');
|
|
1104
|
+
expect(snippet).toContain('"event": "test_event"');
|
|
1105
|
+
});
|
|
1106
|
+
|
|
1107
|
+
// L222: config default-arg — call web generator directly without config
|
|
1108
|
+
it('web generator defaults config to {} when config is omitted', () => {
|
|
1109
|
+
const webTarget = SNIPPET_TARGETS.find((t) => t.id === 'web-datalayer-js');
|
|
1110
|
+
const snippet = webTarget.generator({
|
|
1111
|
+
example: { event: 'test_event' },
|
|
1112
|
+
schema: { properties: {} },
|
|
1113
|
+
dataLayerName: 'myDL',
|
|
1114
|
+
});
|
|
1115
|
+
|
|
1116
|
+
expect(snippet).toContain('window.myDL.push');
|
|
1117
|
+
});
|
|
1118
|
+
|
|
1119
|
+
// L227: schema || {} — call web generator with schema undefined
|
|
1120
|
+
it('web generator falls back to empty schema when schema is falsy', () => {
|
|
1121
|
+
const webTarget = SNIPPET_TARGETS.find((t) => t.id === 'web-datalayer-js');
|
|
1122
|
+
const snippet = webTarget.generator({
|
|
1123
|
+
example: { event: 'test_event' },
|
|
1124
|
+
schema: undefined,
|
|
1125
|
+
config: {},
|
|
1126
|
+
});
|
|
1127
|
+
|
|
1128
|
+
expect(snippet).toContain('window.dataLayer.push');
|
|
1129
|
+
expect(snippet).toContain('"event": "test_event"');
|
|
1130
|
+
});
|
|
1131
|
+
|
|
1132
|
+
// L265: example || {} — call firebase generator with example undefined (throws before L265, but exercises the path)
|
|
1133
|
+
it('toFirebaseParamEntries handles null example via || {} fallback', () => {
|
|
1134
|
+
const kotlinTarget = SNIPPET_TARGETS.find(
|
|
1135
|
+
(t) => t.id === 'android-firebase-kotlin-sdk',
|
|
1136
|
+
);
|
|
1137
|
+
// example with only event triggers toFirebaseParamEntries with a truthy example
|
|
1138
|
+
// but no additional params — the || {} fallback is defensive
|
|
1139
|
+
const snippet = kotlinTarget.generator({
|
|
1140
|
+
example: { event: 'simple_event' },
|
|
1141
|
+
targetId: 'android-firebase-kotlin-sdk',
|
|
1142
|
+
});
|
|
1143
|
+
|
|
1144
|
+
expect(snippet).toContain('firebaseAnalytics.logEvent("simple_event")');
|
|
1145
|
+
});
|
|
1146
|
+
|
|
1147
|
+
// L289: predefined event with objc platform — kFIREvent constant
|
|
1148
|
+
it('uses kFIREvent constant for predefined event in objc snippet', () => {
|
|
1149
|
+
const snippet = generateSnippetForTarget({
|
|
1150
|
+
targetId: 'ios-firebase-objc-sdk',
|
|
1151
|
+
example: {
|
|
1152
|
+
event: 'purchase',
|
|
1153
|
+
transaction_id: 'T_100',
|
|
1154
|
+
},
|
|
1155
|
+
schema: { properties: {} },
|
|
1156
|
+
});
|
|
1157
|
+
|
|
1158
|
+
expect(snippet).toContain(
|
|
1159
|
+
'[FIRAnalytics logEventWithName:kFIREventPurchase parameters:eventParams];',
|
|
1160
|
+
);
|
|
1161
|
+
});
|
|
1162
|
+
|
|
1163
|
+
// L306: predefined param with objc platform — kFIRParameter constant
|
|
1164
|
+
it('uses kFIRParameter constant for predefined param in objc snippet', () => {
|
|
1165
|
+
const snippet = generateSnippetForTarget({
|
|
1166
|
+
targetId: 'ios-firebase-objc-sdk',
|
|
1167
|
+
example: {
|
|
1168
|
+
event: 'custom_event',
|
|
1169
|
+
currency: 'USD',
|
|
1170
|
+
},
|
|
1171
|
+
schema: { properties: {} },
|
|
1172
|
+
});
|
|
1173
|
+
|
|
1174
|
+
expect(snippet).toContain('kFIRParameterCurrency: @"USD"');
|
|
1175
|
+
});
|
|
744
1176
|
});
|