@oneuptime/common 10.8.2 → 11.0.1
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/Models/AnalyticsModels/AnalyticsBaseModel/AnalyticsBaseModel.ts +16 -18
- package/Models/AnalyticsModels/AuditLog.ts +3 -1
- package/Models/AnalyticsModels/ExceptionInstance.ts +200 -82
- package/Models/AnalyticsModels/Index.ts +7 -2
- package/Models/AnalyticsModels/Log.ts +197 -81
- package/Models/AnalyticsModels/Metric.ts +199 -86
- package/Models/AnalyticsModels/MetricBaselineHourly.ts +44 -25
- package/Models/AnalyticsModels/MetricItemAggMV1m.ts +23 -20
- package/Models/AnalyticsModels/{MetricItemAggMV1mByHost.ts → MetricItemAggMV1mByHostV2.ts} +58 -47
- package/Models/AnalyticsModels/MonitorLog.ts +5 -1
- package/Models/AnalyticsModels/Profile.ts +206 -85
- package/Models/AnalyticsModels/ProfileSample.ts +196 -83
- package/Models/AnalyticsModels/Span.ts +218 -85
- package/Models/DatabaseModels/Index.ts +4 -0
- package/Models/DatabaseModels/Service.ts +29 -0
- package/Models/DatabaseModels/TelemetryEntity.ts +393 -0
- package/Models/DatabaseModels/TelemetryEntityRelationship.ts +294 -0
- package/Models/DatabaseModels/TelemetryException.ts +10 -10
- package/Models/DatabaseModels/TelemetryUsageBilling.ts +5 -5
- package/Server/API/AIAgentDataAPI.ts +13 -12
- package/Server/API/DashboardAPI.ts +2 -2
- package/Server/API/TelemetryAPI.ts +656 -141
- package/Server/API/TelemetryExceptionAPI.ts +2 -2
- package/Server/Infrastructure/ClickhouseConfig.ts +12 -0
- package/Server/Infrastructure/Postgres/SchemaMigrations/1781100000001-RenameTelemetryServiceIdToPrimaryEntityId.ts +48 -0
- package/Server/Infrastructure/Postgres/SchemaMigrations/1781200000000-AddTelemetryEntityTable.ts +70 -0
- package/Server/Infrastructure/Postgres/SchemaMigrations/1781200000001-AddTelemetryEntityRelationshipTable.ts +57 -0
- package/Server/Infrastructure/Postgres/SchemaMigrations/1781250074195-MigrationName.ts +207 -0
- package/Server/Infrastructure/Postgres/SchemaMigrations/1781300000000-AddTelemetryEntityLabels.ts +24 -0
- package/Server/Infrastructure/Postgres/SchemaMigrations/1781400000000-AddServiceTelemetrySdkLanguage.ts +25 -0
- package/Server/Infrastructure/Postgres/SchemaMigrations/Index.ts +12 -0
- package/Server/Infrastructure/Queue.ts +36 -3
- package/Server/Middleware/TelemetryIngest.ts +27 -22
- package/Server/Services/AlertService.ts +9 -9
- package/Server/Services/AnalyticsDatabaseService.ts +204 -35
- package/Server/Services/ExceptionAggregationService.ts +41 -18
- package/Server/Services/HostService.ts +2 -1
- package/Server/Services/IncidentService.ts +19 -19
- package/Server/Services/Index.ts +6 -2
- package/Server/Services/LogAggregationService.ts +116 -43
- package/Server/Services/MetricAggregationService.ts +29 -14
- package/Server/Services/MetricBaselineService.ts +34 -34
- package/Server/Services/MetricItemAggMV1mByHostV2Service.ts +30 -0
- package/Server/Services/MetricService.ts +119 -31
- package/Server/Services/OpenTelemetryIngestService.ts +186 -50
- package/Server/Services/ProfileAggregationService.ts +904 -126
- package/Server/Services/ServiceService.ts +6 -0
- package/Server/Services/SpanService.ts +274 -14
- package/Server/Services/TelemetryEntityRelationshipService.ts +71 -0
- package/Server/Services/TelemetryEntityService.ts +246 -0
- package/Server/Services/TelemetryExceptionService.ts +27 -23
- package/Server/Services/TelemetryUsageBillingService.ts +38 -31
- package/Server/Services/TraceAggregationService.ts +875 -43
- package/Server/Types/AnalyticsDatabase/ModelPermission.ts +43 -2
- package/Server/Types/Database/Permissions/AccessControlPermission.ts +47 -2
- package/Server/Types/Database/Permissions/BasePermission.ts +37 -1
- package/Server/Types/Database/Permissions/OwnedScopePermission.ts +21 -3
- package/Server/Types/Database/Permissions/OwnerTableRegistry.ts +1 -0
- package/Server/Types/Database/QueryHelper.ts +41 -0
- package/Server/Utils/Alert/AlertPrivacyFilter.ts +9 -2
- package/Server/Utils/AlertEpisode/AlertEpisodePrivacyFilter.ts +9 -2
- package/Server/Utils/AnalyticsDatabase/QuerySettingsHelper.ts +95 -0
- package/Server/Utils/AnalyticsDatabase/StatementGenerator.ts +133 -0
- package/Server/Utils/Incident/IncidentPrivacyFilter.ts +9 -2
- package/Server/Utils/IncidentEpisode/IncidentEpisodePrivacyFilter.ts +9 -2
- package/Server/Utils/Monitor/Criteria/EvaluateOverTime.ts +1 -1
- package/Server/Utils/Monitor/MonitorLogUtil.ts +1 -2
- package/Server/Utils/Monitor/MonitorMetricUtil.ts +3 -4
- package/Server/Utils/PrivacyFilterUtil.ts +72 -0
- package/Server/Utils/Profile/PprofEncoder.ts +135 -11
- package/Server/Utils/Telemetry/EntityRegistry.ts +316 -0
- package/Server/Utils/Telemetry/ResourceFacetResolver.ts +5 -0
- package/Server/Utils/Telemetry/TelemetryEntity.ts +783 -0
- package/Tests/Server/Services/AnalyticsDatabaseService.test.ts +79 -4
- package/Tests/Server/Services/LogAggregationService.test.ts +7 -2
- package/Tests/Server/Services/ProfileAggregationService.test.ts +280 -0
- package/Tests/Server/Services/ProfileBreakdown.test.ts +161 -0
- package/Tests/Server/Services/ProfileFunctionFocus.test.ts +349 -0
- package/Tests/Server/Services/TelemetryAttributeService.test.ts +1 -1
- package/Tests/Server/Services/TraceAggregationService.test.ts +403 -0
- package/Tests/Server/Types/AnalyticsDatabase/ModelPermissionOwnedScope.test.ts +114 -0
- package/Tests/Server/Types/Database/Permissions/AccessControlPermission.test.ts +189 -0
- package/Tests/Server/Types/Database/Permissions/BasePermission.test.ts +118 -0
- package/Tests/Server/Types/Database/Permissions/OwnedScopePermission.test.ts +159 -0
- package/Tests/Server/Utils/AnalyticsDatabase/StatementGenerator.test.ts +275 -8
- package/Tests/Server/Utils/PrivacyFilterUtil.test.ts +177 -0
- package/Tests/Server/Utils/Profile/PprofEncoder.test.ts +276 -0
- package/Tests/Server/Utils/Telemetry/TelemetryEntity.test.ts +761 -0
- package/Tests/Types/Monitor/MonitorStepEntityScope.test.ts +275 -0
- package/Tests/Types/Text.test.ts +52 -0
- package/Tests/Utils/ModelImportExport.test.ts +366 -0
- package/Tests/Utils/Telemetry/EntityKey.test.ts +150 -0
- package/Tests/Utils/Telemetry/EntityKeySqlParity.test.ts +40 -0
- package/Tests/Utils/Telemetry/EntityRelationship.test.ts +150 -0
- package/Tests/Utils/UUID.test.ts +47 -0
- package/Types/AnalyticsDatabase/AnalyticsTableName.ts +14 -9
- package/Types/AnalyticsDatabase/TableColumnType.ts +1 -0
- package/Types/Dashboard/DashboardComponentType.ts +1 -0
- package/Types/Dashboard/DashboardComponents/DashboardTraceChartComponent.ts +37 -0
- package/Types/Dashboard/DashboardTemplates.ts +4 -5
- package/Types/Log/LogQueryParser.ts +2 -2
- package/Types/Log/LogQueryToFilter.ts +2 -2
- package/Types/Monitor/MonitorStepExceptionMonitor.ts +19 -1
- package/Types/Monitor/MonitorStepLogMonitor.ts +20 -1
- package/Types/Monitor/MonitorStepMetricMonitor.ts +27 -0
- package/Types/Monitor/MonitorStepProfileMonitor.ts +19 -1
- package/Types/Monitor/MonitorStepTraceMonitor.ts +18 -1
- package/Types/Monitor/MonitorType.ts +8 -1
- package/Types/ObjectID.ts +10 -0
- package/Types/Telemetry/EntityRelationshipType.ts +31 -0
- package/Types/Telemetry/EntityType.ts +33 -0
- package/Types/Telemetry/TelemetrySavedViewState.ts +2 -0
- package/Types/Text.ts +34 -0
- package/Types/Trace/TraceAggregationType.ts +1 -0
- package/Types/Trace/TraceRecordingRuleDefinition.ts +74 -0
- package/UI/Components/ImportExport/ExportModelCard.tsx +90 -0
- package/UI/Components/ImportExport/ImportModelsModal.tsx +239 -0
- package/UI/Components/LogsViewer/LogsViewer.tsx +12 -9
- package/UI/Components/LogsViewer/components/LogDetailsPanel.tsx +10 -9
- package/UI/Components/LogsViewer/components/LogSearchBar.tsx +1 -1
- package/UI/Components/LogsViewer/components/LogsAnalyticsView.tsx +2 -2
- package/UI/Components/LogsViewer/components/LogsFacetSidebar.tsx +4 -4
- package/UI/Components/LogsViewer/components/LogsTable.tsx +5 -3
- package/UI/Components/ModelTable/ModelTable.tsx +294 -143
- package/UI/Components/Navbar/NavBarMenuModal.tsx +81 -44
- package/UI/Components/TelemetryViewer/TelemetryViewer.tsx +33 -10
- package/UI/Components/TelemetryViewer/components/TelemetryFacetSidebar.tsx +18 -3
- package/UI/Components/TelemetryViewer/components/TelemetryHistogram.tsx +91 -68
- package/UI/Components/TelemetryViewer/components/TelemetryHistogramTooltip.tsx +9 -2
- package/UI/Utils/LogExport.ts +2 -2
- package/UI/Utils/ModelImportExport.ts +207 -0
- package/UI/Utils/TelemetryService.ts +20 -20
- package/Utils/Dashboard/Components/DashboardTraceChartComponent.ts +134 -0
- package/Utils/Dashboard/Components/Index.ts +7 -0
- package/Utils/ModelImportExport.ts +369 -0
- package/Utils/Telemetry/EntityKey.ts +151 -0
- package/Utils/Telemetry/EntityRelationship.ts +113 -0
- package/Utils/Traces/CriticalPath.ts +7 -7
- package/Utils/UUID.ts +57 -0
- package/build/dist/Models/AnalyticsModels/AnalyticsBaseModel/AnalyticsBaseModel.js +14 -13
- package/build/dist/Models/AnalyticsModels/AnalyticsBaseModel/AnalyticsBaseModel.js.map +1 -1
- package/build/dist/Models/AnalyticsModels/AuditLog.js +2 -1
- package/build/dist/Models/AnalyticsModels/AuditLog.js.map +1 -1
- package/build/dist/Models/AnalyticsModels/ExceptionInstance.js +125 -22
- package/build/dist/Models/AnalyticsModels/ExceptionInstance.js.map +1 -1
- package/build/dist/Models/AnalyticsModels/Index.js +7 -2
- package/build/dist/Models/AnalyticsModels/Index.js.map +1 -1
- package/build/dist/Models/AnalyticsModels/Log.js +123 -22
- package/build/dist/Models/AnalyticsModels/Log.js.map +1 -1
- package/build/dist/Models/AnalyticsModels/Metric.js +125 -27
- package/build/dist/Models/AnalyticsModels/Metric.js.map +1 -1
- package/build/dist/Models/AnalyticsModels/MetricBaselineHourly.js +38 -21
- package/build/dist/Models/AnalyticsModels/MetricBaselineHourly.js.map +1 -1
- package/build/dist/Models/AnalyticsModels/MetricItemAggMV1m.js +17 -16
- package/build/dist/Models/AnalyticsModels/MetricItemAggMV1m.js.map +1 -1
- package/build/dist/Models/AnalyticsModels/{MetricItemAggMV1mByHost.js → MetricItemAggMV1mByHostV2.js} +54 -42
- package/build/dist/Models/AnalyticsModels/MetricItemAggMV1mByHostV2.js.map +1 -0
- package/build/dist/Models/AnalyticsModels/MonitorLog.js +4 -1
- package/build/dist/Models/AnalyticsModels/MonitorLog.js.map +1 -1
- package/build/dist/Models/AnalyticsModels/Profile.js +132 -26
- package/build/dist/Models/AnalyticsModels/Profile.js.map +1 -1
- package/build/dist/Models/AnalyticsModels/ProfileSample.js +121 -23
- package/build/dist/Models/AnalyticsModels/ProfileSample.js.map +1 -1
- package/build/dist/Models/AnalyticsModels/Span.js +144 -26
- package/build/dist/Models/AnalyticsModels/Span.js.map +1 -1
- package/build/dist/Models/DatabaseModels/Index.js +4 -0
- package/build/dist/Models/DatabaseModels/Index.js.map +1 -1
- package/build/dist/Models/DatabaseModels/Service.js +30 -0
- package/build/dist/Models/DatabaseModels/Service.js.map +1 -1
- package/build/dist/Models/DatabaseModels/TelemetryEntity.js +419 -0
- package/build/dist/Models/DatabaseModels/TelemetryEntity.js.map +1 -0
- package/build/dist/Models/DatabaseModels/TelemetryEntityRelationship.js +317 -0
- package/build/dist/Models/DatabaseModels/TelemetryEntityRelationship.js.map +1 -0
- package/build/dist/Models/DatabaseModels/TelemetryException.js +12 -12
- package/build/dist/Models/DatabaseModels/TelemetryException.js.map +1 -1
- package/build/dist/Models/DatabaseModels/TelemetryUsageBilling.js +7 -7
- package/build/dist/Models/DatabaseModels/TelemetryUsageBilling.js.map +1 -1
- package/build/dist/Server/API/AIAgentDataAPI.js +14 -13
- package/build/dist/Server/API/AIAgentDataAPI.js.map +1 -1
- package/build/dist/Server/API/DashboardAPI.js +2 -2
- package/build/dist/Server/API/DashboardAPI.js.map +1 -1
- package/build/dist/Server/API/TelemetryAPI.js +425 -129
- package/build/dist/Server/API/TelemetryAPI.js.map +1 -1
- package/build/dist/Server/API/TelemetryExceptionAPI.js +2 -2
- package/build/dist/Server/API/TelemetryExceptionAPI.js.map +1 -1
- package/build/dist/Server/Infrastructure/ClickhouseConfig.js +12 -0
- package/build/dist/Server/Infrastructure/ClickhouseConfig.js.map +1 -1
- package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1781100000001-RenameTelemetryServiceIdToPrimaryEntityId.js +29 -0
- package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1781100000001-RenameTelemetryServiceIdToPrimaryEntityId.js.map +1 -0
- package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1781200000000-AddTelemetryEntityTable.js +38 -0
- package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1781200000000-AddTelemetryEntityTable.js.map +1 -0
- package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1781200000001-AddTelemetryEntityRelationshipTable.js +33 -0
- package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1781200000001-AddTelemetryEntityRelationshipTable.js.map +1 -0
- package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1781250074195-MigrationName.js +78 -0
- package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1781250074195-MigrationName.js.map +1 -0
- package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1781300000000-AddTelemetryEntityLabels.js +19 -0
- package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1781300000000-AddTelemetryEntityLabels.js.map +1 -0
- package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1781400000000-AddServiceTelemetrySdkLanguage.js +18 -0
- package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1781400000000-AddServiceTelemetrySdkLanguage.js.map +1 -0
- package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/Index.js +12 -0
- package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/Index.js.map +1 -1
- package/build/dist/Server/Infrastructure/Queue.js +14 -3
- package/build/dist/Server/Infrastructure/Queue.js.map +1 -1
- package/build/dist/Server/Middleware/TelemetryIngest.js +16 -18
- package/build/dist/Server/Middleware/TelemetryIngest.js.map +1 -1
- package/build/dist/Server/Services/AlertService.js +9 -9
- package/build/dist/Server/Services/AlertService.js.map +1 -1
- package/build/dist/Server/Services/AnalyticsDatabaseService.js +115 -40
- package/build/dist/Server/Services/AnalyticsDatabaseService.js.map +1 -1
- package/build/dist/Server/Services/ExceptionAggregationService.js +38 -18
- package/build/dist/Server/Services/ExceptionAggregationService.js.map +1 -1
- package/build/dist/Server/Services/HostService.js +2 -1
- package/build/dist/Server/Services/HostService.js.map +1 -1
- package/build/dist/Server/Services/IncidentService.js +19 -19
- package/build/dist/Server/Services/IncidentService.js.map +1 -1
- package/build/dist/Server/Services/Index.js +6 -2
- package/build/dist/Server/Services/Index.js.map +1 -1
- package/build/dist/Server/Services/LogAggregationService.js +100 -42
- package/build/dist/Server/Services/LogAggregationService.js.map +1 -1
- package/build/dist/Server/Services/MetricAggregationService.js +27 -14
- package/build/dist/Server/Services/MetricAggregationService.js.map +1 -1
- package/build/dist/Server/Services/MetricBaselineService.js +28 -28
- package/build/dist/Server/Services/MetricBaselineService.js.map +1 -1
- package/build/dist/Server/Services/MetricItemAggMV1mByHostV2Service.js +28 -0
- package/build/dist/Server/Services/MetricItemAggMV1mByHostV2Service.js.map +1 -0
- package/build/dist/Server/Services/MetricService.js +116 -31
- package/build/dist/Server/Services/MetricService.js.map +1 -1
- package/build/dist/Server/Services/OpenTelemetryIngestService.js +103 -36
- package/build/dist/Server/Services/OpenTelemetryIngestService.js.map +1 -1
- package/build/dist/Server/Services/ProfileAggregationService.js +613 -105
- package/build/dist/Server/Services/ProfileAggregationService.js.map +1 -1
- package/build/dist/Server/Services/ServiceService.js +9 -5
- package/build/dist/Server/Services/ServiceService.js.map +1 -1
- package/build/dist/Server/Services/SpanService.js +217 -15
- package/build/dist/Server/Services/SpanService.js.map +1 -1
- package/build/dist/Server/Services/TelemetryEntityRelationshipService.js +72 -0
- package/build/dist/Server/Services/TelemetryEntityRelationshipService.js.map +1 -0
- package/build/dist/Server/Services/TelemetryEntityService.js +201 -0
- package/build/dist/Server/Services/TelemetryEntityService.js.map +1 -0
- package/build/dist/Server/Services/TelemetryExceptionService.js +18 -18
- package/build/dist/Server/Services/TelemetryExceptionService.js.map +1 -1
- package/build/dist/Server/Services/TelemetryUsageBillingService.js +27 -21
- package/build/dist/Server/Services/TelemetryUsageBillingService.js.map +1 -1
- package/build/dist/Server/Services/TraceAggregationService.js +568 -43
- package/build/dist/Server/Services/TraceAggregationService.js.map +1 -1
- package/build/dist/Server/Types/AnalyticsDatabase/ModelPermission.js +38 -2
- package/build/dist/Server/Types/AnalyticsDatabase/ModelPermission.js.map +1 -1
- package/build/dist/Server/Types/Database/Permissions/AccessControlPermission.js +36 -2
- package/build/dist/Server/Types/Database/Permissions/AccessControlPermission.js.map +1 -1
- package/build/dist/Server/Types/Database/Permissions/BasePermission.js +25 -1
- package/build/dist/Server/Types/Database/Permissions/BasePermission.js.map +1 -1
- package/build/dist/Server/Types/Database/Permissions/OwnedScopePermission.js +17 -3
- package/build/dist/Server/Types/Database/Permissions/OwnedScopePermission.js.map +1 -1
- package/build/dist/Server/Types/Database/Permissions/OwnerTableRegistry.js +1 -0
- package/build/dist/Server/Types/Database/Permissions/OwnerTableRegistry.js.map +1 -1
- package/build/dist/Server/Types/Database/QueryHelper.js +31 -0
- package/build/dist/Server/Types/Database/QueryHelper.js.map +1 -1
- package/build/dist/Server/Utils/Alert/AlertPrivacyFilter.js +3 -2
- package/build/dist/Server/Utils/Alert/AlertPrivacyFilter.js.map +1 -1
- package/build/dist/Server/Utils/AlertEpisode/AlertEpisodePrivacyFilter.js +3 -2
- package/build/dist/Server/Utils/AlertEpisode/AlertEpisodePrivacyFilter.js.map +1 -1
- package/build/dist/Server/Utils/AnalyticsDatabase/QuerySettingsHelper.js +46 -0
- package/build/dist/Server/Utils/AnalyticsDatabase/QuerySettingsHelper.js.map +1 -0
- package/build/dist/Server/Utils/AnalyticsDatabase/StatementGenerator.js +97 -3
- package/build/dist/Server/Utils/AnalyticsDatabase/StatementGenerator.js.map +1 -1
- package/build/dist/Server/Utils/Incident/IncidentPrivacyFilter.js +3 -2
- package/build/dist/Server/Utils/Incident/IncidentPrivacyFilter.js.map +1 -1
- package/build/dist/Server/Utils/IncidentEpisode/IncidentEpisodePrivacyFilter.js +3 -2
- package/build/dist/Server/Utils/IncidentEpisode/IncidentEpisodePrivacyFilter.js.map +1 -1
- package/build/dist/Server/Utils/Monitor/Criteria/EvaluateOverTime.js +1 -1
- package/build/dist/Server/Utils/Monitor/Criteria/EvaluateOverTime.js.map +1 -1
- package/build/dist/Server/Utils/Monitor/MonitorLogUtil.js +1 -2
- package/build/dist/Server/Utils/Monitor/MonitorLogUtil.js.map +1 -1
- package/build/dist/Server/Utils/Monitor/MonitorMetricUtil.js +3 -4
- package/build/dist/Server/Utils/Monitor/MonitorMetricUtil.js.map +1 -1
- package/build/dist/Server/Utils/PrivacyFilterUtil.js +47 -0
- package/build/dist/Server/Utils/PrivacyFilterUtil.js.map +1 -0
- package/build/dist/Server/Utils/Profile/PprofEncoder.js +132 -4
- package/build/dist/Server/Utils/Profile/PprofEncoder.js.map +1 -1
- package/build/dist/Server/Utils/Telemetry/EntityRegistry.js +228 -0
- package/build/dist/Server/Utils/Telemetry/EntityRegistry.js.map +1 -0
- package/build/dist/Server/Utils/Telemetry/ResourceFacetResolver.js +5 -0
- package/build/dist/Server/Utils/Telemetry/ResourceFacetResolver.js.map +1 -1
- package/build/dist/Server/Utils/Telemetry/TelemetryEntity.js +569 -0
- package/build/dist/Server/Utils/Telemetry/TelemetryEntity.js.map +1 -0
- package/build/dist/Types/AnalyticsDatabase/AnalyticsTableName.js +14 -9
- package/build/dist/Types/AnalyticsDatabase/AnalyticsTableName.js.map +1 -1
- package/build/dist/Types/AnalyticsDatabase/TableColumnType.js +1 -0
- package/build/dist/Types/AnalyticsDatabase/TableColumnType.js.map +1 -1
- package/build/dist/Types/Dashboard/DashboardComponentType.js +1 -0
- package/build/dist/Types/Dashboard/DashboardComponentType.js.map +1 -1
- package/build/dist/Types/Dashboard/DashboardComponents/DashboardTraceChartComponent.js +2 -0
- package/build/dist/Types/Dashboard/DashboardComponents/DashboardTraceChartComponent.js.map +1 -0
- package/build/dist/Types/Dashboard/DashboardTemplates.js +4 -5
- package/build/dist/Types/Dashboard/DashboardTemplates.js.map +1 -1
- package/build/dist/Types/Log/LogQueryParser.js +2 -2
- package/build/dist/Types/Log/LogQueryParser.js.map +1 -1
- package/build/dist/Types/Log/LogQueryToFilter.js +1 -1
- package/build/dist/Types/Log/LogQueryToFilter.js.map +1 -1
- package/build/dist/Types/Monitor/MonitorStepExceptionMonitor.js +9 -1
- package/build/dist/Types/Monitor/MonitorStepExceptionMonitor.js.map +1 -1
- package/build/dist/Types/Monitor/MonitorStepLogMonitor.js +9 -1
- package/build/dist/Types/Monitor/MonitorStepLogMonitor.js.map +1 -1
- package/build/dist/Types/Monitor/MonitorStepMetricMonitor.js +13 -0
- package/build/dist/Types/Monitor/MonitorStepMetricMonitor.js.map +1 -1
- package/build/dist/Types/Monitor/MonitorStepProfileMonitor.js +9 -1
- package/build/dist/Types/Monitor/MonitorStepProfileMonitor.js.map +1 -1
- package/build/dist/Types/Monitor/MonitorStepTraceMonitor.js +9 -1
- package/build/dist/Types/Monitor/MonitorStepTraceMonitor.js.map +1 -1
- package/build/dist/Types/Monitor/MonitorType.js +8 -1
- package/build/dist/Types/Monitor/MonitorType.js.map +1 -1
- package/build/dist/Types/ObjectID.js +9 -0
- package/build/dist/Types/ObjectID.js.map +1 -1
- package/build/dist/Types/Telemetry/EntityRelationshipType.js +32 -0
- package/build/dist/Types/Telemetry/EntityRelationshipType.js.map +1 -0
- package/build/dist/Types/Telemetry/EntityType.js +34 -0
- package/build/dist/Types/Telemetry/EntityType.js.map +1 -0
- package/build/dist/Types/Text.js +32 -1
- package/build/dist/Types/Text.js.map +1 -1
- package/build/dist/Types/Trace/TraceAggregationType.js +1 -0
- package/build/dist/Types/Trace/TraceAggregationType.js.map +1 -1
- package/build/dist/Types/Trace/TraceRecordingRuleDefinition.js +50 -1
- package/build/dist/Types/Trace/TraceRecordingRuleDefinition.js.map +1 -1
- package/build/dist/UI/Components/ImportExport/ExportModelCard.js +50 -0
- package/build/dist/UI/Components/ImportExport/ExportModelCard.js.map +1 -0
- package/build/dist/UI/Components/ImportExport/ImportModelsModal.js +115 -0
- package/build/dist/UI/Components/ImportExport/ImportModelsModal.js.map +1 -0
- package/build/dist/UI/Components/LogsViewer/LogsViewer.js +10 -9
- package/build/dist/UI/Components/LogsViewer/LogsViewer.js.map +1 -1
- package/build/dist/UI/Components/LogsViewer/components/LogDetailsPanel.js +8 -8
- package/build/dist/UI/Components/LogsViewer/components/LogDetailsPanel.js.map +1 -1
- package/build/dist/UI/Components/LogsViewer/components/LogSearchBar.js +1 -1
- package/build/dist/UI/Components/LogsViewer/components/LogSearchBar.js.map +1 -1
- package/build/dist/UI/Components/LogsViewer/components/LogsAnalyticsView.js +2 -2
- package/build/dist/UI/Components/LogsViewer/components/LogsAnalyticsView.js.map +1 -1
- package/build/dist/UI/Components/LogsViewer/components/LogsFacetSidebar.js +4 -4
- package/build/dist/UI/Components/LogsViewer/components/LogsFacetSidebar.js.map +1 -1
- package/build/dist/UI/Components/LogsViewer/components/LogsTable.js +3 -3
- package/build/dist/UI/Components/LogsViewer/components/LogsTable.js.map +1 -1
- package/build/dist/UI/Components/ModelTable/ModelTable.js +166 -74
- package/build/dist/UI/Components/ModelTable/ModelTable.js.map +1 -1
- package/build/dist/UI/Components/Navbar/NavBarMenuModal.js +43 -30
- package/build/dist/UI/Components/Navbar/NavBarMenuModal.js.map +1 -1
- package/build/dist/UI/Components/TelemetryViewer/TelemetryViewer.js +6 -2
- package/build/dist/UI/Components/TelemetryViewer/TelemetryViewer.js.map +1 -1
- package/build/dist/UI/Components/TelemetryViewer/components/TelemetryFacetSidebar.js +14 -3
- package/build/dist/UI/Components/TelemetryViewer/components/TelemetryFacetSidebar.js.map +1 -1
- package/build/dist/UI/Components/TelemetryViewer/components/TelemetryHistogram.js +18 -10
- package/build/dist/UI/Components/TelemetryViewer/components/TelemetryHistogram.js.map +1 -1
- package/build/dist/UI/Components/TelemetryViewer/components/TelemetryHistogramTooltip.js +4 -2
- package/build/dist/UI/Components/TelemetryViewer/components/TelemetryHistogramTooltip.js.map +1 -1
- package/build/dist/UI/Utils/LogExport.js +2 -2
- package/build/dist/UI/Utils/LogExport.js.map +1 -1
- package/build/dist/UI/Utils/ModelImportExport.js +142 -0
- package/build/dist/UI/Utils/ModelImportExport.js.map +1 -0
- package/build/dist/UI/Utils/TelemetryService.js +16 -16
- package/build/dist/UI/Utils/TelemetryService.js.map +1 -1
- package/build/dist/Utils/Dashboard/Components/DashboardTraceChartComponent.js +110 -0
- package/build/dist/Utils/Dashboard/Components/DashboardTraceChartComponent.js.map +1 -0
- package/build/dist/Utils/Dashboard/Components/Index.js +4 -0
- package/build/dist/Utils/Dashboard/Components/Index.js.map +1 -1
- package/build/dist/Utils/ModelImportExport.js +257 -0
- package/build/dist/Utils/ModelImportExport.js.map +1 -0
- package/build/dist/Utils/Telemetry/EntityKey.js +115 -0
- package/build/dist/Utils/Telemetry/EntityKey.js.map +1 -0
- package/build/dist/Utils/Telemetry/EntityRelationship.js +71 -0
- package/build/dist/Utils/Telemetry/EntityRelationship.js.map +1 -0
- package/build/dist/Utils/Traces/CriticalPath.js +5 -5
- package/build/dist/Utils/Traces/CriticalPath.js.map +1 -1
- package/build/dist/Utils/UUID.js +50 -0
- package/build/dist/Utils/UUID.js.map +1 -1
- package/package.json +2 -1
- package/tsconfig.json +10 -1
- package/Server/Services/MetricItemAggMV1mByHostService.ts +0 -30
- package/Types/Profile/ProfileMetricType.ts +0 -16
- package/build/dist/Models/AnalyticsModels/MetricItemAggMV1mByHost.js.map +0 -1
- package/build/dist/Server/Services/MetricItemAggMV1mByHostService.js +0 -28
- package/build/dist/Server/Services/MetricItemAggMV1mByHostService.js.map +0 -1
- package/build/dist/Tests/MockType.js +0 -5
- package/build/dist/Tests/MockType.js.map +0 -1
- package/build/dist/Tests/Models/AnalyticsModels/Log.test.js +0 -12
- package/build/dist/Tests/Models/AnalyticsModels/Log.test.js.map +0 -1
- package/build/dist/Tests/Models/File.test.js +0 -10
- package/build/dist/Tests/Models/File.test.js.map +0 -1
- package/build/dist/Tests/Server/API/BaseAPI.test.js +0 -590
- package/build/dist/Tests/Server/API/BaseAPI.test.js.map +0 -1
- package/build/dist/Tests/Server/API/Helpers.js +0 -27
- package/build/dist/Tests/Server/API/Helpers.js.map +0 -1
- package/build/dist/Tests/Server/API/ProbeAPI.test.js +0 -84
- package/build/dist/Tests/Server/API/ProbeAPI.test.js.map +0 -1
- package/build/dist/Tests/Server/API/ProjectAPI.test.js +0 -170
- package/build/dist/Tests/Server/API/ProjectAPI.test.js.map +0 -1
- package/build/dist/Tests/Server/API/UserSmsApi.test.js +0 -177
- package/build/dist/Tests/Server/API/UserSmsApi.test.js.map +0 -1
- package/build/dist/Tests/Server/Middleware/BearerTokenAuthorization.test.js +0 -63
- package/build/dist/Tests/Server/Middleware/BearerTokenAuthorization.test.js.map +0 -1
- package/build/dist/Tests/Server/Middleware/ClusterKeyAuthorization.test.js +0 -58
- package/build/dist/Tests/Server/Middleware/ClusterKeyAuthorization.test.js.map +0 -1
- package/build/dist/Tests/Server/Middleware/NotificationMiddleware.test.js +0 -101
- package/build/dist/Tests/Server/Middleware/NotificationMiddleware.test.js.map +0 -1
- package/build/dist/Tests/Server/Middleware/ProjectAuthorization.test.js +0 -160
- package/build/dist/Tests/Server/Middleware/ProjectAuthorization.test.js.map +0 -1
- package/build/dist/Tests/Server/Middleware/UserAuthorization.test.js +0 -410
- package/build/dist/Tests/Server/Middleware/UserAuthorization.test.js.map +0 -1
- package/build/dist/Tests/Server/Services/AlertEpisodeMemberService.test.js +0 -165
- package/build/dist/Tests/Server/Services/AlertEpisodeMemberService.test.js.map +0 -1
- package/build/dist/Tests/Server/Services/AlertEpisodeService.test.js +0 -193
- package/build/dist/Tests/Server/Services/AlertEpisodeService.test.js.map +0 -1
- package/build/dist/Tests/Server/Services/AlertGroupingEngineService.test.js +0 -435
- package/build/dist/Tests/Server/Services/AlertGroupingEngineService.test.js.map +0 -1
- package/build/dist/Tests/Server/Services/AlertGroupingRuleService.test.js +0 -320
- package/build/dist/Tests/Server/Services/AlertGroupingRuleService.test.js.map +0 -1
- package/build/dist/Tests/Server/Services/AnalyticsDatabaseService.test.js +0 -266
- package/build/dist/Tests/Server/Services/AnalyticsDatabaseService.test.js.map +0 -1
- package/build/dist/Tests/Server/Services/BillingService.test.js +0 -910
- package/build/dist/Tests/Server/Services/BillingService.test.js.map +0 -1
- package/build/dist/Tests/Server/Services/LogAggregationService.test.js +0 -75
- package/build/dist/Tests/Server/Services/LogAggregationService.test.js.map +0 -1
- package/build/dist/Tests/Server/Services/ProbeService.test.js +0 -127
- package/build/dist/Tests/Server/Services/ProbeService.test.js.map +0 -1
- package/build/dist/Tests/Server/Services/ScheduledMaintenanceService.test.js +0 -114
- package/build/dist/Tests/Server/Services/ScheduledMaintenanceService.test.js.map +0 -1
- package/build/dist/Tests/Server/Services/TeamMemberService.test.js +0 -106
- package/build/dist/Tests/Server/Services/TeamMemberService.test.js.map +0 -1
- package/build/dist/Tests/Server/Services/TelemetryAttributeService.test.js +0 -50
- package/build/dist/Tests/Server/Services/TelemetryAttributeService.test.js.map +0 -1
- package/build/dist/Tests/Server/TestingUtils/Init.js +0 -4
- package/build/dist/Tests/Server/TestingUtils/Init.js.map +0 -1
- package/build/dist/Tests/Server/TestingUtils/Postgres/TestDataSourceOptions.js +0 -9
- package/build/dist/Tests/Server/TestingUtils/Postgres/TestDataSourceOptions.js.map +0 -1
- package/build/dist/Tests/Server/TestingUtils/Redis/TestRedisOptions.js +0 -16
- package/build/dist/Tests/Server/TestingUtils/Redis/TestRedisOptions.js.map +0 -1
- package/build/dist/Tests/Server/TestingUtils/Services/BillingServiceHelper.js +0 -125
- package/build/dist/Tests/Server/TestingUtils/Services/BillingServiceHelper.js.map +0 -1
- package/build/dist/Tests/Server/TestingUtils/Services/ProjectServiceHelper.js +0 -39
- package/build/dist/Tests/Server/TestingUtils/Services/ProjectServiceHelper.js.map +0 -1
- package/build/dist/Tests/Server/TestingUtils/Services/ScheduledMaintenanceServiceHelper.js +0 -20
- package/build/dist/Tests/Server/TestingUtils/Services/ScheduledMaintenanceServiceHelper.js.map +0 -1
- package/build/dist/Tests/Server/TestingUtils/Services/ScheduledMaintenanceStateServiceHelper.js +0 -31
- package/build/dist/Tests/Server/TestingUtils/Services/ScheduledMaintenanceStateServiceHelper.js.map +0 -1
- package/build/dist/Tests/Server/TestingUtils/Services/TeamMemberServiceHelper.js +0 -14
- package/build/dist/Tests/Server/TestingUtils/Services/TeamMemberServiceHelper.js.map +0 -1
- package/build/dist/Tests/Server/TestingUtils/Services/TeamServiceHelper.js +0 -21
- package/build/dist/Tests/Server/TestingUtils/Services/TeamServiceHelper.js.map +0 -1
- package/build/dist/Tests/Server/TestingUtils/Services/Types.js +0 -2
- package/build/dist/Tests/Server/TestingUtils/Services/Types.js.map +0 -1
- package/build/dist/Tests/Server/TestingUtils/Services/UserServiceHelper.js +0 -37
- package/build/dist/Tests/Server/TestingUtils/Services/UserServiceHelper.js.map +0 -1
- package/build/dist/Tests/Server/TestingUtils/__mocks__/Stripe.mock.js +0 -13
- package/build/dist/Tests/Server/TestingUtils/__mocks__/Stripe.mock.js.map +0 -1
- package/build/dist/Tests/Server/TestingUtils/__mocks__/TestDatabase.mock.js +0 -22
- package/build/dist/Tests/Server/TestingUtils/__mocks__/TestDatabase.mock.js.map +0 -1
- package/build/dist/Tests/Server/Types/Domain.test.js +0 -78
- package/build/dist/Tests/Server/Types/Domain.test.js.map +0 -1
- package/build/dist/Tests/Server/Utils/AnalyticsDatabase/Statement.test.js +0 -94
- package/build/dist/Tests/Server/Utils/AnalyticsDatabase/Statement.test.js.map +0 -1
- package/build/dist/Tests/Server/Utils/AnalyticsDatabase/StatementGenerator.test.js +0 -459
- package/build/dist/Tests/Server/Utils/AnalyticsDatabase/StatementGenerator.test.js.map +0 -1
- package/build/dist/Tests/Server/Utils/Cookie.test.js +0 -83
- package/build/dist/Tests/Server/Utils/Cookie.test.js.map +0 -1
- package/build/dist/Tests/Server/Utils/CronTab.test.js +0 -29
- package/build/dist/Tests/Server/Utils/CronTab.test.js.map +0 -1
- package/build/dist/Tests/Server/Utils/JsonToCsv.test.js +0 -114
- package/build/dist/Tests/Server/Utils/JsonToCsv.test.js.map +0 -1
- package/build/dist/Tests/Server/Utils/Monitor/Criteria/MetricMonitorCriteria.test.js +0 -606
- package/build/dist/Tests/Server/Utils/Monitor/Criteria/MetricMonitorCriteria.test.js.map +0 -1
- package/build/dist/Tests/Server/Utils/Monitor/Criteria/SnmpMonitorCriteria.test.js +0 -255
- package/build/dist/Tests/Server/Utils/Monitor/Criteria/SnmpMonitorCriteria.test.js.map +0 -1
- package/build/dist/Tests/Server/Utils/Monitor/MonitorMaintenanceSuppression.test.js +0 -142
- package/build/dist/Tests/Server/Utils/Monitor/MonitorMaintenanceSuppression.test.js.map +0 -1
- package/build/dist/Tests/Server/Utils/StatusPageResource.test.js +0 -122
- package/build/dist/Tests/Server/Utils/StatusPageResource.test.js.map +0 -1
- package/build/dist/Tests/Server/Utils/Telemetry/LogExceptionExtractor.test.js +0 -0
- package/build/dist/Tests/Server/Utils/Telemetry/LogExceptionExtractor.test.js.map +0 -1
- package/build/dist/Tests/Server/Utils/VM/VMAPI.test.js +0 -205
- package/build/dist/Tests/Server/Utils/VM/VMAPI.test.js.map +0 -1
- package/build/dist/Tests/Spy.js +0 -4
- package/build/dist/Tests/Spy.js.map +0 -1
- package/build/dist/Tests/Types/API/ErrorResponse.test.js +0 -13
- package/build/dist/Tests/Types/API/ErrorResponse.test.js.map +0 -1
- package/build/dist/Tests/Types/API/HTTPErrorResponse.test.js +0 -33
- package/build/dist/Tests/Types/API/HTTPErrorResponse.test.js.map +0 -1
- package/build/dist/Tests/Types/API/HTTPMethod.test.js +0 -16
- package/build/dist/Tests/Types/API/HTTPMethod.test.js.map +0 -1
- package/build/dist/Tests/Types/API/Headers.test.js +0 -14
- package/build/dist/Tests/Types/API/Headers.test.js.map +0 -1
- package/build/dist/Tests/Types/API/Hostname.test.js +0 -22
- package/build/dist/Tests/Types/API/Hostname.test.js.map +0 -1
- package/build/dist/Tests/Types/API/Protocal.test.js +0 -19
- package/build/dist/Tests/Types/API/Protocal.test.js.map +0 -1
- package/build/dist/Tests/Types/API/Response.test.js +0 -14
- package/build/dist/Tests/Types/API/Response.test.js.map +0 -1
- package/build/dist/Tests/Types/API/ResponseType.test.js +0 -13
- package/build/dist/Tests/Types/API/ResponseType.test.js.map +0 -1
- package/build/dist/Tests/Types/API/Route.test.js +0 -30
- package/build/dist/Tests/Types/API/Route.test.js.map +0 -1
- package/build/dist/Tests/Types/API/StatusCode.test.js +0 -26
- package/build/dist/Tests/Types/API/StatusCode.test.js.map +0 -1
- package/build/dist/Tests/Types/API/URL.test.js +0 -33
- package/build/dist/Tests/Types/API/URL.test.js.map +0 -1
- package/build/dist/Tests/Types/Alerts/AlertEventType.test.js +0 -34
- package/build/dist/Tests/Types/Alerts/AlertEventType.test.js.map +0 -1
- package/build/dist/Tests/Types/Alerts/AlertType.test.js +0 -19
- package/build/dist/Tests/Types/Alerts/AlertType.test.js.map +0 -1
- package/build/dist/Tests/Types/AppEnvironment.test.js +0 -13
- package/build/dist/Tests/Types/AppEnvironment.test.js.map +0 -1
- package/build/dist/Tests/Types/ApplicationLog/ApplicationLogType.test.js +0 -13
- package/build/dist/Tests/Types/ApplicationLog/ApplicationLogType.test.js.map +0 -1
- package/build/dist/Tests/Types/ArrayUtil.test.js +0 -71
- package/build/dist/Tests/Types/ArrayUtil.test.js.map +0 -1
- package/build/dist/Tests/Types/Billing/SubscriptionPlan.test.js +0 -181
- package/build/dist/Tests/Types/Billing/SubscriptionPlan.test.js.map +0 -1
- package/build/dist/Tests/Types/BrandColors.test.js +0 -124
- package/build/dist/Tests/Types/BrandColors.test.js.map +0 -1
- package/build/dist/Tests/Types/Char.test.js +0 -82
- package/build/dist/Tests/Types/Char.test.js.map +0 -1
- package/build/dist/Tests/Types/Code/CodeType.test.js +0 -13
- package/build/dist/Tests/Types/Code/CodeType.test.js.map +0 -1
- package/build/dist/Tests/Types/Color.test.js +0 -44
- package/build/dist/Tests/Types/Color.test.js.map +0 -1
- package/build/dist/Tests/Types/Company/CompanySize.test.js +0 -20
- package/build/dist/Tests/Types/Company/CompanySize.test.js.map +0 -1
- package/build/dist/Tests/Types/Company/JobRole.test.js +0 -22
- package/build/dist/Tests/Types/Company/JobRole.test.js.map +0 -1
- package/build/dist/Tests/Types/Countries.test.js +0 -249
- package/build/dist/Tests/Types/Countries.test.js.map +0 -1
- package/build/dist/Tests/Types/Database/ColumnLength.test.js +0 -43
- package/build/dist/Tests/Types/Database/ColumnLength.test.js.map +0 -1
- package/build/dist/Tests/Types/Database/ColumnType.test.js +0 -79
- package/build/dist/Tests/Types/Database/ColumnType.test.js.map +0 -1
- package/build/dist/Tests/Types/Database/Columns.test.js +0 -20
- package/build/dist/Tests/Types/Database/Columns.test.js.map +0 -1
- package/build/dist/Tests/Types/Database/CompareBase.test.js +0 -37
- package/build/dist/Tests/Types/Database/CompareBase.test.js.map +0 -1
- package/build/dist/Tests/Types/Database/Date.test.js +0 -62
- package/build/dist/Tests/Types/Database/Date.test.js.map +0 -1
- package/build/dist/Tests/Types/Database/EqualTo.test.js +0 -65
- package/build/dist/Tests/Types/Database/EqualTo.test.js.map +0 -1
- package/build/dist/Tests/Types/Database/EqualToOrNull.test.js +0 -62
- package/build/dist/Tests/Types/Database/EqualToOrNull.test.js.map +0 -1
- package/build/dist/Tests/Types/Database/InBetween.test.js +0 -72
- package/build/dist/Tests/Types/Database/InBetween.test.js.map +0 -1
- package/build/dist/Tests/Types/Database/LimitMax.test.js +0 -18
- package/build/dist/Tests/Types/Database/LimitMax.test.js.map +0 -1
- package/build/dist/Tests/Types/Database/NotEqual.test.js +0 -19
- package/build/dist/Tests/Types/Database/NotEqual.test.js.map +0 -1
- package/build/dist/Tests/Types/Database/Search.test.js +0 -10
- package/build/dist/Tests/Types/Database/Search.test.js.map +0 -1
- package/build/dist/Tests/Types/DatabaseType.test.js +0 -7
- package/build/dist/Tests/Types/DatabaseType.test.js.map +0 -1
- package/build/dist/Tests/Types/Date.test.js +0 -194
- package/build/dist/Tests/Types/Date.test.js.map +0 -1
- package/build/dist/Tests/Types/Dictionary.test.js +0 -25
- package/build/dist/Tests/Types/Dictionary.test.js.map +0 -1
- package/build/dist/Tests/Types/Domain.test.js +0 -54
- package/build/dist/Tests/Types/Domain.test.js.map +0 -1
- package/build/dist/Tests/Types/Email/Email.test.js +0 -51
- package/build/dist/Tests/Types/Email/Email.test.js.map +0 -1
- package/build/dist/Tests/Types/EmailWithName.test.js +0 -36
- package/build/dist/Tests/Types/EmailWithName.test.js.map +0 -1
- package/build/dist/Tests/Types/EncryptionAlgorithm.test.js +0 -7
- package/build/dist/Tests/Types/EncryptionAlgorithm.test.js.map +0 -1
- package/build/dist/Tests/Types/Exception/ApiException.test.js +0 -10
- package/build/dist/Tests/Types/Exception/ApiException.test.js.map +0 -1
- package/build/dist/Tests/Types/Exception/BadDataException.test.js +0 -12
- package/build/dist/Tests/Types/Exception/BadDataException.test.js.map +0 -1
- package/build/dist/Tests/Types/Exception/BadOperationException.test.js +0 -10
- package/build/dist/Tests/Types/Exception/BadOperationException.test.js.map +0 -1
- package/build/dist/Tests/Types/Exception/BadRequestException.test.js +0 -12
- package/build/dist/Tests/Types/Exception/BadRequestException.test.js.map +0 -1
- package/build/dist/Tests/Types/Exception/DatabaseNotConnectedException.test.js +0 -10
- package/build/dist/Tests/Types/Exception/DatabaseNotConnectedException.test.js.map +0 -1
- package/build/dist/Tests/Types/Exception/Exception.test.js +0 -15
- package/build/dist/Tests/Types/Exception/Exception.test.js.map +0 -1
- package/build/dist/Tests/Types/Exception/NotImplementedException.test.js +0 -12
- package/build/dist/Tests/Types/Exception/NotImplementedException.test.js.map +0 -1
- package/build/dist/Tests/Types/File.test.js +0 -22
- package/build/dist/Tests/Types/File.test.js.map +0 -1
- package/build/dist/Tests/Types/HashedString.test.js +0 -51
- package/build/dist/Tests/Types/HashedString.test.js.map +0 -1
- package/build/dist/Tests/Types/Html.test.js +0 -8
- package/build/dist/Tests/Types/Html.test.js.map +0 -1
- package/build/dist/Tests/Types/IP/IP.test.js +0 -65
- package/build/dist/Tests/Types/IP/IP.test.js.map +0 -1
- package/build/dist/Tests/Types/IP/IPType.test.js +0 -10
- package/build/dist/Tests/Types/IP/IPType.test.js.map +0 -1
- package/build/dist/Tests/Types/IP/IPv4.test.js +0 -17
- package/build/dist/Tests/Types/IP/IPv4.test.js.map +0 -1
- package/build/dist/Tests/Types/IP/IPv6.test.js +0 -17
- package/build/dist/Tests/Types/IP/IPv6.test.js.map +0 -1
- package/build/dist/Tests/Types/JSON.test.js +0 -37
- package/build/dist/Tests/Types/JSON.test.js.map +0 -1
- package/build/dist/Tests/Types/JSONFunctions.test.js +0 -38
- package/build/dist/Tests/Types/JSONFunctions.test.js.map +0 -1
- package/build/dist/Tests/Types/ListData.test.js +0 -34
- package/build/dist/Tests/Types/ListData.test.js.map +0 -1
- package/build/dist/Tests/Types/Monitor/KubernetesAlertTemplates.test.js +0 -121
- package/build/dist/Tests/Types/Monitor/KubernetesAlertTemplates.test.js.map +0 -1
- package/build/dist/Tests/Types/Name.test.js +0 -26
- package/build/dist/Tests/Types/Name.test.js.map +0 -1
- package/build/dist/Tests/Types/ObjectID.test.js +0 -12
- package/build/dist/Tests/Types/ObjectID.test.js.map +0 -1
- package/build/dist/Tests/Types/OnCallDutyPolicy/LayerUtil.test.js +0 -530
- package/build/dist/Tests/Types/OnCallDutyPolicy/LayerUtil.test.js.map +0 -1
- package/build/dist/Tests/Types/Permission.test.js +0 -99
- package/build/dist/Tests/Types/Permission.test.js.map +0 -1
- package/build/dist/Tests/Types/Phone.test.js +0 -37
- package/build/dist/Tests/Types/Phone.test.js.map +0 -1
- package/build/dist/Tests/Types/Port.test.js +0 -35
- package/build/dist/Tests/Types/Port.test.js.map +0 -1
- package/build/dist/Tests/Types/PositiveNumber.test.js +0 -101
- package/build/dist/Tests/Types/PositiveNumber.test.js.map +0 -1
- package/build/dist/Tests/Types/SecuritySeverity.test.js +0 -16
- package/build/dist/Tests/Types/SecuritySeverity.test.js.map +0 -1
- package/build/dist/Tests/Types/SerializableObject.test.js +0 -37
- package/build/dist/Tests/Types/SerializableObject.test.js.map +0 -1
- package/build/dist/Tests/Types/Sleep.test.js +0 -14
- package/build/dist/Tests/Types/Sleep.test.js.map +0 -1
- package/build/dist/Tests/Types/Text.test.js +0 -8
- package/build/dist/Tests/Types/Text.test.js.map +0 -1
- package/build/dist/Tests/Types/Timezone.test.js +0 -596
- package/build/dist/Tests/Types/Timezone.test.js.map +0 -1
- package/build/dist/Tests/Types/Typeof.test.js +0 -16
- package/build/dist/Tests/Types/Typeof.test.js.map +0 -1
- package/build/dist/Tests/Types/UserType.test.js +0 -16
- package/build/dist/Tests/Types/UserType.test.js.map +0 -1
- package/build/dist/Tests/Types/Version.test.js +0 -35
- package/build/dist/Tests/Types/Version.test.js.map +0 -1
- package/build/dist/Tests/Types/XML.test.js +0 -35
- package/build/dist/Tests/Types/XML.test.js.map +0 -1
- package/build/dist/Tests/UI/Components/404.test.js +0 -59
- package/build/dist/Tests/UI/Components/404.test.js.map +0 -1
- package/build/dist/Tests/UI/Components/Alert.test.js +0 -83
- package/build/dist/Tests/UI/Components/Alert.test.js.map +0 -1
- package/build/dist/Tests/UI/Components/Badge.test.js +0 -59
- package/build/dist/Tests/UI/Components/Badge.test.js.map +0 -1
- package/build/dist/Tests/UI/Components/BasicForm.test.js +0 -92
- package/build/dist/Tests/UI/Components/BasicForm.test.js.map +0 -1
- package/build/dist/Tests/UI/Components/Breadcrumbs.test.js +0 -69
- package/build/dist/Tests/UI/Components/Breadcrumbs.test.js.map +0 -1
- package/build/dist/Tests/UI/Components/Button.test.js +0 -104
- package/build/dist/Tests/UI/Components/Button.test.js.map +0 -1
- package/build/dist/Tests/UI/Components/Card.test.js +0 -81
- package/build/dist/Tests/UI/Components/Card.test.js.map +0 -1
- package/build/dist/Tests/UI/Components/ColorViewer.test.js +0 -42
- package/build/dist/Tests/UI/Components/ColorViewer.test.js.map +0 -1
- package/build/dist/Tests/UI/Components/ComponentsModal.test.js +0 -233
- package/build/dist/Tests/UI/Components/ComponentsModal.test.js.map +0 -1
- package/build/dist/Tests/UI/Components/ConfirmModal.test.js +0 -57
- package/build/dist/Tests/UI/Components/ConfirmModal.test.js.map +0 -1
- package/build/dist/Tests/UI/Components/DictionaryOfStrings.test.js +0 -84
- package/build/dist/Tests/UI/Components/DictionaryOfStrings.test.js.map +0 -1
- package/build/dist/Tests/UI/Components/Dropdown.test.js +0 -146
- package/build/dist/Tests/UI/Components/Dropdown.test.js.map +0 -1
- package/build/dist/Tests/UI/Components/DuplicateModel.test.js +0 -229
- package/build/dist/Tests/UI/Components/DuplicateModel.test.js.map +0 -1
- package/build/dist/Tests/UI/Components/EmptyState/EmptyState.test.js +0 -26
- package/build/dist/Tests/UI/Components/EmptyState/EmptyState.test.js.map +0 -1
- package/build/dist/Tests/UI/Components/ErrorBoundary.test.js +0 -32
- package/build/dist/Tests/UI/Components/ErrorBoundary.test.js.map +0 -1
- package/build/dist/Tests/UI/Components/FilePicker.test.js +0 -342
- package/build/dist/Tests/UI/Components/FilePicker.test.js.map +0 -1
- package/build/dist/Tests/UI/Components/HiddenText.test.js +0 -50
- package/build/dist/Tests/UI/Components/HiddenText.test.js.map +0 -1
- package/build/dist/Tests/UI/Components/Input.test.js +0 -223
- package/build/dist/Tests/UI/Components/Input.test.js.map +0 -1
- package/build/dist/Tests/UI/Components/Item.test.js +0 -58
- package/build/dist/Tests/UI/Components/Item.test.js.map +0 -1
- package/build/dist/Tests/UI/Components/List.test.js +0 -83
- package/build/dist/Tests/UI/Components/List.test.js.map +0 -1
- package/build/dist/Tests/UI/Components/Loader.test.js +0 -19
- package/build/dist/Tests/UI/Components/Loader.test.js.map +0 -1
- package/build/dist/Tests/UI/Components/MarkdownEditor.test.js +0 -85
- package/build/dist/Tests/UI/Components/MarkdownEditor.test.js.map +0 -1
- package/build/dist/Tests/UI/Components/MasterPage.test.js +0 -46
- package/build/dist/Tests/UI/Components/MasterPage.test.js.map +0 -1
- package/build/dist/Tests/UI/Components/Modal.test.js +0 -127
- package/build/dist/Tests/UI/Components/Modal.test.js.map +0 -1
- package/build/dist/Tests/UI/Components/NavBar.test.js +0 -52
- package/build/dist/Tests/UI/Components/NavBar.test.js.map +0 -1
- package/build/dist/Tests/UI/Components/OrderedStatesList.test.js +0 -86
- package/build/dist/Tests/UI/Components/OrderedStatesList.test.js.map +0 -1
- package/build/dist/Tests/UI/Components/Pagination.test.js +0 -137
- package/build/dist/Tests/UI/Components/Pagination.test.js.map +0 -1
- package/build/dist/Tests/UI/Components/Pill.test.js +0 -55
- package/build/dist/Tests/UI/Components/Pill.test.js.map +0 -1
- package/build/dist/Tests/UI/Components/Probe.test.js +0 -52
- package/build/dist/Tests/UI/Components/Probe.test.js.map +0 -1
- package/build/dist/Tests/UI/Components/ProgressBar.test.js +0 -41
- package/build/dist/Tests/UI/Components/ProgressBar.test.js.map +0 -1
- package/build/dist/Tests/UI/Components/RadioButtons.test.js +0 -66
- package/build/dist/Tests/UI/Components/RadioButtons.test.js.map +0 -1
- package/build/dist/Tests/UI/Components/SideMenuItem.test.js +0 -99
- package/build/dist/Tests/UI/Components/SideMenuItem.test.js.map +0 -1
- package/build/dist/Tests/UI/Components/SideOver.test.js +0 -77
- package/build/dist/Tests/UI/Components/SideOver.test.js.map +0 -1
- package/build/dist/Tests/UI/Components/Tabs.test.js +0 -56
- package/build/dist/Tests/UI/Components/Tabs.test.js.map +0 -1
- package/build/dist/Tests/UI/Components/Template/Template.test.js +0 -15
- package/build/dist/Tests/UI/Components/Template/Template.test.js.map +0 -1
- package/build/dist/Tests/UI/Components/TextArea.test.js +0 -112
- package/build/dist/Tests/UI/Components/TextArea.test.js.map +0 -1
- package/build/dist/Tests/UI/Components/TimePicker/TimePicker.test.js +0 -352
- package/build/dist/Tests/UI/Components/TimePicker/TimePicker.test.js.map +0 -1
- package/build/dist/Tests/UI/Components/Toast.test.js +0 -48
- package/build/dist/Tests/UI/Components/Toast.test.js.map +0 -1
- package/build/dist/Tests/UI/Components/Toggle.test.js +0 -95
- package/build/dist/Tests/UI/Components/Toggle.test.js.map +0 -1
- package/build/dist/Tests/UI/Components/TopSection.test.js +0 -33
- package/build/dist/Tests/UI/Components/TopSection.test.js.map +0 -1
- package/build/dist/Tests/UI/Components/XAxis.test.js +0 -21
- package/build/dist/Tests/UI/Components/XAxis.test.js.map +0 -1
- package/build/dist/Tests/UI/Index.js +0 -2
- package/build/dist/Tests/UI/Index.js.map +0 -1
- package/build/dist/Tests/UI/Mocks/FileMock.js +0 -3
- package/build/dist/Tests/UI/Mocks/FileMock.js.map +0 -1
- package/build/dist/Tests/Utils/API.test.js +0 -399
- package/build/dist/Tests/Utils/API.test.js.map +0 -1
- package/build/dist/Tests/Utils/Analytics.test.js +0 -67
- package/build/dist/Tests/Utils/Analytics.test.js.map +0 -1
- package/build/dist/Tests/Utils/CronTime.test.js +0 -22
- package/build/dist/Tests/Utils/CronTime.test.js.map +0 -1
- package/build/dist/Tests/Utils/Faker.test.js +0 -27
- package/build/dist/Tests/Utils/Faker.test.js.map +0 -1
- package/build/dist/Tests/Utils/MetricUnitUtil.test.js +0 -187
- package/build/dist/Tests/Utils/MetricUnitUtil.test.js.map +0 -1
- package/build/dist/Tests/Utils/Metrics/MetricFormulaEvaluator.test.js +0 -224
- package/build/dist/Tests/Utils/Metrics/MetricFormulaEvaluator.test.js.map +0 -1
- package/build/dist/Tests/Utils/Metrics/MetricResultUnitConverter.test.js +0 -180
- package/build/dist/Tests/Utils/Metrics/MetricResultUnitConverter.test.js.map +0 -1
- package/build/dist/Tests/Utils/RecordingRuleExpression.test.js +0 -142
- package/build/dist/Tests/Utils/RecordingRuleExpression.test.js.map +0 -1
- package/build/dist/Tests/Utils/Slug.test.js +0 -20
- package/build/dist/Tests/Utils/Slug.test.js.map +0 -1
- package/build/dist/Tests/Utils/UUID.test.js +0 -48
- package/build/dist/Tests/Utils/UUID.test.js.map +0 -1
- package/build/dist/Tests/jest.setup.js +0 -30
- package/build/dist/Tests/jest.setup.js.map +0 -1
- package/build/dist/Types/Profile/ProfileMetricType.js +0 -17
- package/build/dist/Types/Profile/ProfileMetricType.js.map +0 -1
|
@@ -1,910 +0,0 @@
|
|
|
1
|
-
import getJestMockFunction from "../../MockType";
|
|
2
|
-
import { ActiveMonitoringMeteredPlan } from "../../../Server/Types/Billing/MeteredPlan/AllMeteredPlans";
|
|
3
|
-
import Errors from "../../../Server/Utils/Errors";
|
|
4
|
-
import { getChangePlanData, getCouponData, getCustomerData, getMeteredSubscription, getStripeCustomer, getStripeInvoice, getStripeSubscription, getSubscriptionData, getSubscriptionPlanData, mockIsBillingEnabled, } from "../TestingUtils/Services/BillingServiceHelper";
|
|
5
|
-
import { mockStripe } from "../TestingUtils/__mocks__/Stripe.mock";
|
|
6
|
-
import { describe, expect, beforeEach, jest } from "@jest/globals";
|
|
7
|
-
import MeteredPlan from "../../../Types/Billing/MeteredPlan";
|
|
8
|
-
import SubscriptionStatus from "../../../Types/Billing/SubscriptionStatus";
|
|
9
|
-
import OneUptimeDate from "../../../Types/Date";
|
|
10
|
-
describe("BillingService", () => {
|
|
11
|
-
let billingService;
|
|
12
|
-
const customer = getCustomerData();
|
|
13
|
-
const mockCustomer = getStripeCustomer(customer.id.toString());
|
|
14
|
-
beforeEach(async () => {
|
|
15
|
-
jest.clearAllMocks();
|
|
16
|
-
billingService = await mockIsBillingEnabled(true);
|
|
17
|
-
}, 10 * 1000);
|
|
18
|
-
describe("Customer Management", () => {
|
|
19
|
-
describe("createCustomer", () => {
|
|
20
|
-
it("should create a customer when valid data is provided", async () => {
|
|
21
|
-
mockStripe.customers.create =
|
|
22
|
-
getJestMockFunction().mockResolvedValue(mockCustomer);
|
|
23
|
-
const result = await billingService.createCustomer(customer);
|
|
24
|
-
expect(result).toEqual(mockCustomer.id);
|
|
25
|
-
expect(mockStripe.customers.create).toHaveBeenCalledWith({
|
|
26
|
-
name: customer.name,
|
|
27
|
-
email: customer.email.toString(),
|
|
28
|
-
metadata: {
|
|
29
|
-
id: customer.id.toString(),
|
|
30
|
-
},
|
|
31
|
-
});
|
|
32
|
-
expect(result).toBe(mockCustomer.id);
|
|
33
|
-
});
|
|
34
|
-
it("should throw an exception if billing is not enabled", async () => {
|
|
35
|
-
billingService = await mockIsBillingEnabled(false);
|
|
36
|
-
await expect(billingService.createCustomer(customer)).rejects.toThrow(Errors.BillingService.BILLING_NOT_ENABLED);
|
|
37
|
-
});
|
|
38
|
-
});
|
|
39
|
-
describe("updateCustomerName", () => {
|
|
40
|
-
it("should successfully update a customer name", async () => {
|
|
41
|
-
const newName = "newName";
|
|
42
|
-
await billingService.updateCustomerName(customer.id.toString(), newName);
|
|
43
|
-
expect(mockStripe.customers.update).toHaveBeenCalledWith(customer.id.toString(), { name: newName });
|
|
44
|
-
});
|
|
45
|
-
it("should throw an exception if billing is not enabled for updating customer name", async () => {
|
|
46
|
-
billingService = await mockIsBillingEnabled(false);
|
|
47
|
-
await expect(billingService.updateCustomerName("cust_123", "Jane Doe")).rejects.toThrow(Errors.BillingService.BILLING_NOT_ENABLED);
|
|
48
|
-
});
|
|
49
|
-
});
|
|
50
|
-
describe("deleteCustomer", () => {
|
|
51
|
-
it("should successfully delete a customer", async () => {
|
|
52
|
-
await billingService.deleteCustomer(customer.id.toString());
|
|
53
|
-
expect(mockStripe.customers.del).toHaveBeenCalledWith(customer.id.toString());
|
|
54
|
-
});
|
|
55
|
-
it("should throw an exception if billing is not enabled for deleting customer", async () => {
|
|
56
|
-
billingService = await mockIsBillingEnabled(false);
|
|
57
|
-
await expect(billingService.deleteCustomer("cust_123")).rejects.toThrow(Errors.BillingService.BILLING_NOT_ENABLED);
|
|
58
|
-
});
|
|
59
|
-
});
|
|
60
|
-
});
|
|
61
|
-
describe("Subscription Management", () => {
|
|
62
|
-
Object.defineProperty(global, "performance", {
|
|
63
|
-
writable: true,
|
|
64
|
-
});
|
|
65
|
-
let mockDate = OneUptimeDate.getCurrentDate();
|
|
66
|
-
let mockSubscription;
|
|
67
|
-
const subscription = getSubscriptionData();
|
|
68
|
-
const subscriptionPlan = getSubscriptionPlanData();
|
|
69
|
-
const meteredSubscription = getMeteredSubscription(subscriptionPlan);
|
|
70
|
-
beforeEach(() => {
|
|
71
|
-
mockSubscription = getStripeSubscription();
|
|
72
|
-
mockDate = OneUptimeDate.getCurrentDate();
|
|
73
|
-
});
|
|
74
|
-
describe("subscribeToMeteredPlan", () => {
|
|
75
|
-
it("should successfully create a metered plan subscription with all required parameters", async () => {
|
|
76
|
-
mockStripe.subscriptions.create =
|
|
77
|
-
getJestMockFunction().mockResolvedValue(mockSubscription);
|
|
78
|
-
const result = await billingService.subscribeToMeteredPlan(subscription);
|
|
79
|
-
expect(mockStripe.subscriptions.create).toHaveBeenCalledWith(expect.objectContaining({
|
|
80
|
-
customer: subscription.customerId,
|
|
81
|
-
items: [],
|
|
82
|
-
trial_end: "now",
|
|
83
|
-
}));
|
|
84
|
-
expect(result.meteredSubscriptionId).toBe(mockSubscription.id);
|
|
85
|
-
expect(result.trialEndsAt).toBe(subscription.trialDate);
|
|
86
|
-
});
|
|
87
|
-
it("should create a metered plan subscription with a trial date in the future", async () => {
|
|
88
|
-
const futureDate = new Date();
|
|
89
|
-
futureDate.setDate(futureDate.getDate() + 10); // 10 days in the future
|
|
90
|
-
subscription.trialDate = futureDate;
|
|
91
|
-
mockStripe.subscriptions.create =
|
|
92
|
-
getJestMockFunction().mockResolvedValue(mockSubscription);
|
|
93
|
-
await billingService.subscribeToMeteredPlan(subscription);
|
|
94
|
-
expect(mockStripe.subscriptions.create).toHaveBeenCalledWith(expect.objectContaining({
|
|
95
|
-
trial_end: Math.floor(subscription.trialDate.getTime() / 1000),
|
|
96
|
-
}));
|
|
97
|
-
});
|
|
98
|
-
it("should create a subscription without a trial when the trial date is not in the future", async () => {
|
|
99
|
-
const pastDate = new Date("2020-01-01");
|
|
100
|
-
subscription.trialDate = pastDate;
|
|
101
|
-
mockStripe.subscriptions.create =
|
|
102
|
-
getJestMockFunction().mockResolvedValue(mockSubscription);
|
|
103
|
-
await billingService.subscribeToMeteredPlan(subscription);
|
|
104
|
-
expect(mockStripe.subscriptions.create).toHaveBeenCalledWith(expect.objectContaining({
|
|
105
|
-
trial_end: "now",
|
|
106
|
-
}));
|
|
107
|
-
});
|
|
108
|
-
it("should handle API errors during subscription creation", async () => {
|
|
109
|
-
mockStripe.subscriptions.create =
|
|
110
|
-
getJestMockFunction().mockImplementation(() => {
|
|
111
|
-
throw new Error("Stripe API error");
|
|
112
|
-
});
|
|
113
|
-
await expect(billingService.subscribeToMeteredPlan(subscription)).rejects.toThrowError("Stripe API error");
|
|
114
|
-
});
|
|
115
|
-
it("should correctly handle the promo code", async () => {
|
|
116
|
-
subscription.promoCode = "VALIDPROMO";
|
|
117
|
-
mockStripe.subscriptions.create =
|
|
118
|
-
getJestMockFunction().mockResolvedValue(mockSubscription);
|
|
119
|
-
await billingService.subscribeToMeteredPlan(subscription);
|
|
120
|
-
expect(mockStripe.subscriptions.create).toHaveBeenCalledWith(expect.objectContaining({
|
|
121
|
-
coupon: subscription.promoCode,
|
|
122
|
-
}));
|
|
123
|
-
});
|
|
124
|
-
it("should set the default payment method if provided", async () => {
|
|
125
|
-
subscription.defaultPaymentMethodId = "pm_123";
|
|
126
|
-
mockStripe.subscriptions.create =
|
|
127
|
-
getJestMockFunction().mockResolvedValue(mockSubscription);
|
|
128
|
-
await billingService.subscribeToMeteredPlan(subscription);
|
|
129
|
-
expect(mockStripe.subscriptions.create).toHaveBeenCalledWith(expect.objectContaining({
|
|
130
|
-
default_payment_method: subscription.defaultPaymentMethodId,
|
|
131
|
-
}));
|
|
132
|
-
});
|
|
133
|
-
});
|
|
134
|
-
describe("subscribeToPlan", () => {
|
|
135
|
-
it("should not subscribe to plan if billing is not enabled", async () => {
|
|
136
|
-
billingService = await mockIsBillingEnabled(false);
|
|
137
|
-
await expect(billingService.subscribeToPlan(meteredSubscription)).rejects.toThrow(Errors.BillingService.BILLING_NOT_ENABLED);
|
|
138
|
-
});
|
|
139
|
-
it("should successfully subscribe a customer to a plan", async () => {
|
|
140
|
-
var _a, _b;
|
|
141
|
-
const mockSubscription2 = getStripeSubscription();
|
|
142
|
-
mockStripe.subscriptions.create = getJestMockFunction()
|
|
143
|
-
.mockResolvedValueOnce(mockSubscription)
|
|
144
|
-
.mockResolvedValueOnce(mockSubscription2);
|
|
145
|
-
const result = await billingService.subscribeToPlan(meteredSubscription);
|
|
146
|
-
expect(result.subscriptionId).toEqual(mockSubscription.id);
|
|
147
|
-
expect(result.meteredSubscriptionId).toEqual(mockSubscription2.id);
|
|
148
|
-
const datePlusTrialDays = OneUptimeDate.addRemoveDays(mockDate, subscriptionPlan.getTrialPeriod());
|
|
149
|
-
const datePlusTrialDaysNumber = datePlusTrialDays.getTime();
|
|
150
|
-
expect((_a = result.trialEndsAt) === null || _a === void 0 ? void 0 : _a.toString()).toBeTruthy();
|
|
151
|
-
expect((_b = result.trialEndsAt) === null || _b === void 0 ? void 0 : _b.toString()).toEqual(datePlusTrialDays.toString());
|
|
152
|
-
expect(mockStripe.subscriptions.create).toHaveBeenCalledTimes(2);
|
|
153
|
-
expect(mockStripe.subscriptions.create).toHaveBeenNthCalledWith(1, expect.objectContaining({
|
|
154
|
-
customer: meteredSubscription.customerId,
|
|
155
|
-
items: expect.arrayContaining([
|
|
156
|
-
expect.objectContaining({
|
|
157
|
-
price: meteredSubscription.isYearly
|
|
158
|
-
? subscriptionPlan.getYearlyPlanId()
|
|
159
|
-
: subscriptionPlan.getMonthlyPlanId(),
|
|
160
|
-
quantity: meteredSubscription.quantity,
|
|
161
|
-
}),
|
|
162
|
-
]),
|
|
163
|
-
trial_end: Math.floor(datePlusTrialDaysNumber / 1000),
|
|
164
|
-
}));
|
|
165
|
-
expect(mockStripe.subscriptions.create).toHaveBeenNthCalledWith(2, expect.objectContaining({
|
|
166
|
-
customer: meteredSubscription.customerId,
|
|
167
|
-
trial_end: Math.floor(datePlusTrialDaysNumber / 1000),
|
|
168
|
-
}));
|
|
169
|
-
});
|
|
170
|
-
it("should subscribe without a trial when trial is false", async () => {
|
|
171
|
-
meteredSubscription.trial = false;
|
|
172
|
-
const mockSubscription2 = getStripeSubscription();
|
|
173
|
-
mockStripe.subscriptions.create = getJestMockFunction()
|
|
174
|
-
.mockResolvedValueOnce(mockSubscription)
|
|
175
|
-
.mockResolvedValueOnce(mockSubscription2);
|
|
176
|
-
const result = await billingService.subscribeToPlan(meteredSubscription);
|
|
177
|
-
expect(result.subscriptionId).toEqual(mockSubscription.id);
|
|
178
|
-
expect(result.meteredSubscriptionId).toEqual(mockSubscription2.id);
|
|
179
|
-
expect(result.trialEndsAt).toBeNull();
|
|
180
|
-
expect(mockStripe.subscriptions.create).toHaveBeenNthCalledWith(1, expect.objectContaining({
|
|
181
|
-
customer: meteredSubscription.customerId,
|
|
182
|
-
items: expect.arrayContaining([
|
|
183
|
-
expect.objectContaining({
|
|
184
|
-
price: meteredSubscription.isYearly
|
|
185
|
-
? subscriptionPlan.getYearlyPlanId()
|
|
186
|
-
: subscriptionPlan.getMonthlyPlanId(),
|
|
187
|
-
quantity: meteredSubscription.quantity,
|
|
188
|
-
}),
|
|
189
|
-
]),
|
|
190
|
-
trial_end: "now",
|
|
191
|
-
}));
|
|
192
|
-
expect(mockStripe.subscriptions.create).toHaveBeenNthCalledWith(2, expect.objectContaining({
|
|
193
|
-
customer: meteredSubscription.customerId,
|
|
194
|
-
trial_end: "now",
|
|
195
|
-
}));
|
|
196
|
-
});
|
|
197
|
-
it("should apply a promo code if provided", async () => {
|
|
198
|
-
meteredSubscription.promoCode = "PROMO123";
|
|
199
|
-
const mockSubscription2 = getStripeSubscription();
|
|
200
|
-
mockStripe.subscriptions.create = getJestMockFunction()
|
|
201
|
-
.mockResolvedValueOnce(mockSubscription)
|
|
202
|
-
.mockResolvedValueOnce(mockSubscription2);
|
|
203
|
-
const result = await billingService.subscribeToPlan(meteredSubscription);
|
|
204
|
-
expect(result.subscriptionId).toEqual(mockSubscription.id);
|
|
205
|
-
expect(result.meteredSubscriptionId).toEqual(mockSubscription2.id);
|
|
206
|
-
expect(mockStripe.subscriptions.create).toHaveBeenNthCalledWith(1, expect.objectContaining({
|
|
207
|
-
customer: meteredSubscription.customerId,
|
|
208
|
-
items: expect.arrayContaining([
|
|
209
|
-
expect.objectContaining({
|
|
210
|
-
price: meteredSubscription.isYearly
|
|
211
|
-
? subscriptionPlan.getYearlyPlanId()
|
|
212
|
-
: subscriptionPlan.getMonthlyPlanId(),
|
|
213
|
-
quantity: meteredSubscription.quantity,
|
|
214
|
-
}),
|
|
215
|
-
]),
|
|
216
|
-
coupon: meteredSubscription.promoCode,
|
|
217
|
-
}));
|
|
218
|
-
expect(mockStripe.subscriptions.create).toHaveBeenNthCalledWith(2, expect.objectContaining({
|
|
219
|
-
customer: meteredSubscription.customerId,
|
|
220
|
-
coupon: meteredSubscription.promoCode,
|
|
221
|
-
}));
|
|
222
|
-
});
|
|
223
|
-
it("should set the default payment method if provided", async () => {
|
|
224
|
-
meteredSubscription.defaultPaymentMethodId = "pm_123";
|
|
225
|
-
const mockSubscription2 = getStripeSubscription();
|
|
226
|
-
mockStripe.subscriptions.create = getJestMockFunction()
|
|
227
|
-
.mockResolvedValueOnce(mockSubscription)
|
|
228
|
-
.mockResolvedValueOnce(mockSubscription2);
|
|
229
|
-
const result = await billingService.subscribeToPlan(meteredSubscription);
|
|
230
|
-
expect(result.subscriptionId).toEqual(mockSubscription.id);
|
|
231
|
-
expect(result.meteredSubscriptionId).toEqual(mockSubscription2.id);
|
|
232
|
-
expect(mockStripe.subscriptions.create).toHaveBeenNthCalledWith(1, expect.objectContaining({
|
|
233
|
-
customer: meteredSubscription.customerId,
|
|
234
|
-
items: expect.arrayContaining([
|
|
235
|
-
expect.objectContaining({
|
|
236
|
-
price: meteredSubscription.isYearly
|
|
237
|
-
? subscriptionPlan.getYearlyPlanId()
|
|
238
|
-
: subscriptionPlan.getMonthlyPlanId(),
|
|
239
|
-
quantity: meteredSubscription.quantity,
|
|
240
|
-
}),
|
|
241
|
-
]),
|
|
242
|
-
default_payment_method: meteredSubscription.defaultPaymentMethodId,
|
|
243
|
-
}));
|
|
244
|
-
expect(mockStripe.subscriptions.create).toHaveBeenNthCalledWith(2, expect.objectContaining({
|
|
245
|
-
customer: meteredSubscription.customerId,
|
|
246
|
-
default_payment_method: meteredSubscription.defaultPaymentMethodId,
|
|
247
|
-
}));
|
|
248
|
-
});
|
|
249
|
-
});
|
|
250
|
-
describe("changeQuantity", () => {
|
|
251
|
-
it("should not change quantity if billing is not enabled", async () => {
|
|
252
|
-
billingService = await mockIsBillingEnabled(false);
|
|
253
|
-
await expect(billingService.changeQuantity(mockSubscription.id, 1)).rejects.toThrow(Errors.BillingService.BILLING_NOT_ENABLED);
|
|
254
|
-
});
|
|
255
|
-
it("should successfully change the quantity of a subscription", async () => {
|
|
256
|
-
var _a, _b;
|
|
257
|
-
const newQuantity = 2;
|
|
258
|
-
mockStripe.subscriptions.retrieve =
|
|
259
|
-
getJestMockFunction().mockResolvedValue(mockSubscription);
|
|
260
|
-
mockStripe.subscriptions.update =
|
|
261
|
-
getJestMockFunction().mockResolvedValue({});
|
|
262
|
-
await billingService.changeQuantity(mockSubscription.id, newQuantity);
|
|
263
|
-
expect(mockStripe.subscriptions.retrieve).toHaveBeenCalledWith(mockSubscription.id);
|
|
264
|
-
expect(mockStripe.subscriptionItems.update).toHaveBeenCalledWith((_b = (_a = mockSubscription.items) === null || _a === void 0 ? void 0 : _a.data[0]) === null || _b === void 0 ? void 0 : _b.id, {
|
|
265
|
-
quantity: newQuantity,
|
|
266
|
-
});
|
|
267
|
-
});
|
|
268
|
-
it("should handle subscription not found scenario in change quantity", async () => {
|
|
269
|
-
mockStripe.subscriptions.retrieve =
|
|
270
|
-
getJestMockFunction().mockResolvedValue(null);
|
|
271
|
-
await expect(billingService.changeQuantity("invalid_id", 2)).rejects.toThrow(Errors.BillingService.SUBSCRIPTION_NOT_FOUND);
|
|
272
|
-
});
|
|
273
|
-
it("should not change quantity if the subscription is canceled", async () => {
|
|
274
|
-
mockSubscription.status = "canceled";
|
|
275
|
-
mockStripe.subscriptions.retrieve =
|
|
276
|
-
getJestMockFunction().mockResolvedValue(mockSubscription);
|
|
277
|
-
await billingService.changeQuantity(mockSubscription.id, 2);
|
|
278
|
-
expect(mockStripe.subscriptions.retrieve).toHaveBeenCalled();
|
|
279
|
-
expect(mockStripe.subscriptions.update).not.toHaveBeenCalled();
|
|
280
|
-
});
|
|
281
|
-
it("should handle missing subscription item ID in the subscription", async () => {
|
|
282
|
-
mockSubscription.items.data = [];
|
|
283
|
-
mockStripe.subscriptions.retrieve =
|
|
284
|
-
getJestMockFunction().mockResolvedValue(mockSubscription);
|
|
285
|
-
await expect(billingService.changeQuantity(mockSubscription.id, 2)).rejects.toThrow(Errors.BillingService.SUBSCRIPTION_ITEM_NOT_FOUND);
|
|
286
|
-
});
|
|
287
|
-
});
|
|
288
|
-
describe("changePlan", () => {
|
|
289
|
-
const newPlan = getChangePlanData(getSubscriptionPlanData());
|
|
290
|
-
it("should throw if billing is not enabled", async () => {
|
|
291
|
-
billingService = await mockIsBillingEnabled(false);
|
|
292
|
-
await expect(billingService.changePlan(newPlan)).rejects.toThrow(Errors.BillingService.BILLING_NOT_ENABLED);
|
|
293
|
-
});
|
|
294
|
-
it("should successfully change the plan", async () => {
|
|
295
|
-
// mocks
|
|
296
|
-
mockStripe.subscriptions.retrieve =
|
|
297
|
-
getJestMockFunction().mockResolvedValue(mockSubscription);
|
|
298
|
-
mockStripe.subscriptions.del = getJestMockFunction().mockResolvedValue({});
|
|
299
|
-
const newMockSubscription = getStripeSubscription();
|
|
300
|
-
const newMockMeteredSubscription = getStripeSubscription();
|
|
301
|
-
mockStripe.subscriptions.create = getJestMockFunction()
|
|
302
|
-
.mockResolvedValueOnce(newMockSubscription)
|
|
303
|
-
.mockResolvedValueOnce(newMockMeteredSubscription);
|
|
304
|
-
const mockPaymentMethods = [
|
|
305
|
-
{
|
|
306
|
-
id: "pm_123",
|
|
307
|
-
type: "card",
|
|
308
|
-
last4Digits: "4242",
|
|
309
|
-
isDefault: true,
|
|
310
|
-
},
|
|
311
|
-
];
|
|
312
|
-
billingService.getPaymentMethods =
|
|
313
|
-
getJestMockFunction().mockResolvedValue(mockPaymentMethods);
|
|
314
|
-
const result = await billingService.changePlan(newPlan);
|
|
315
|
-
expect(result.subscriptionId).toEqual(newMockSubscription.id);
|
|
316
|
-
expect(result.meteredSubscriptionId).toEqual(newMockMeteredSubscription.id);
|
|
317
|
-
expect(mockStripe.subscriptions.del).toHaveBeenCalled();
|
|
318
|
-
expect(mockStripe.subscriptions.del).toHaveBeenCalled();
|
|
319
|
-
expect(mockStripe.subscriptions.create).toHaveBeenCalled();
|
|
320
|
-
});
|
|
321
|
-
it("should handle errors when the current subscription is not found", async () => {
|
|
322
|
-
mockStripe.subscriptions.retrieve =
|
|
323
|
-
getJestMockFunction().mockResolvedValue(null);
|
|
324
|
-
await expect(billingService.changePlan(newPlan)).rejects.toThrow(Errors.BillingService.SUBSCRIPTION_NOT_FOUND);
|
|
325
|
-
});
|
|
326
|
-
it("should check for active payment methods before changing the plan", async () => {
|
|
327
|
-
mockStripe.subscriptions.retrieve =
|
|
328
|
-
getJestMockFunction().mockResolvedValue(mockSubscription);
|
|
329
|
-
const mockPaymentMethods = Array();
|
|
330
|
-
billingService.getPaymentMethods =
|
|
331
|
-
getJestMockFunction().mockResolvedValue(mockPaymentMethods);
|
|
332
|
-
await expect(billingService.changePlan(newPlan)).rejects.toThrow(Errors.BillingService.NO_PAYMENTS_METHODS);
|
|
333
|
-
});
|
|
334
|
-
});
|
|
335
|
-
describe("isSubscriptionActive", () => {
|
|
336
|
-
it("should return true for an active subscription status", () => {
|
|
337
|
-
const activeStatuses = [
|
|
338
|
-
SubscriptionStatus.Active,
|
|
339
|
-
SubscriptionStatus.Trialing,
|
|
340
|
-
];
|
|
341
|
-
activeStatuses.forEach((status) => {
|
|
342
|
-
expect(billingService.isSubscriptionActive(status)).toBeTruthy();
|
|
343
|
-
});
|
|
344
|
-
});
|
|
345
|
-
it("should return false for an inactive subscription status", () => {
|
|
346
|
-
const inactiveStatuses = [
|
|
347
|
-
SubscriptionStatus.Incomplete,
|
|
348
|
-
SubscriptionStatus.IncompleteExpired,
|
|
349
|
-
SubscriptionStatus.Canceled,
|
|
350
|
-
SubscriptionStatus.Unpaid,
|
|
351
|
-
];
|
|
352
|
-
inactiveStatuses.forEach((status) => {
|
|
353
|
-
expect(billingService.isSubscriptionActive(status)).toBeFalsy();
|
|
354
|
-
});
|
|
355
|
-
});
|
|
356
|
-
});
|
|
357
|
-
describe("addOrUpdateMeteredPricingOnSubscription", () => {
|
|
358
|
-
const quantity = 10;
|
|
359
|
-
it("should throw if billing is not enabled", async () => {
|
|
360
|
-
billingService = await mockIsBillingEnabled(false);
|
|
361
|
-
await expect(billingService.addOrUpdateMeteredPricingOnSubscription(mockSubscription.id, ActiveMonitoringMeteredPlan, quantity)).rejects.toThrow(Errors.BillingService.BILLING_NOT_ENABLED);
|
|
362
|
-
});
|
|
363
|
-
it("should successfully add metered pricing to a subscription", async () => {
|
|
364
|
-
var _a;
|
|
365
|
-
const subscriptionItem = mockSubscription.items.data[0];
|
|
366
|
-
const meteredPlan = new MeteredPlan({
|
|
367
|
-
priceId: ((_a = subscriptionItem === null || subscriptionItem === void 0 ? void 0 : subscriptionItem.price) === null || _a === void 0 ? void 0 : _a.id) || "",
|
|
368
|
-
pricePerUnitInUSD: 100,
|
|
369
|
-
unitName: "unit",
|
|
370
|
-
});
|
|
371
|
-
mockSubscription.items.data = [];
|
|
372
|
-
mockStripe.subscriptions.retrieve =
|
|
373
|
-
getJestMockFunction().mockResolvedValue(mockSubscription);
|
|
374
|
-
mockStripe.subscriptionItems.create =
|
|
375
|
-
getJestMockFunction().mockResolvedValue({ id: "sub_item_123" });
|
|
376
|
-
mockStripe.subscriptionItems.createUsageRecord =
|
|
377
|
-
getJestMockFunction().mockResolvedValue({});
|
|
378
|
-
await billingService.addOrUpdateMeteredPricingOnSubscription(mockSubscription.id, ActiveMonitoringMeteredPlan, quantity);
|
|
379
|
-
expect(mockStripe.subscriptions.retrieve).toHaveBeenCalledWith(mockSubscription.id);
|
|
380
|
-
expect(mockStripe.subscriptionItems.create).toHaveBeenCalledWith({
|
|
381
|
-
subscription: mockSubscription.id,
|
|
382
|
-
price: meteredPlan.getPriceId(),
|
|
383
|
-
});
|
|
384
|
-
expect(mockStripe.subscriptionItems.createUsageRecord).toHaveBeenCalledWith("sub_item_123", { quantity });
|
|
385
|
-
});
|
|
386
|
-
it("should successfully update existing metered pricing on a subscription", async () => {
|
|
387
|
-
const subscriptionItem = mockSubscription.items.data[0];
|
|
388
|
-
mockStripe.subscriptions.retrieve =
|
|
389
|
-
getJestMockFunction().mockResolvedValue(mockSubscription);
|
|
390
|
-
mockStripe.subscriptionItems.createUsageRecord =
|
|
391
|
-
getJestMockFunction().mockResolvedValue({});
|
|
392
|
-
await billingService.addOrUpdateMeteredPricingOnSubscription(mockSubscription.id, ActiveMonitoringMeteredPlan, quantity);
|
|
393
|
-
expect(mockStripe.subscriptions.retrieve).toHaveBeenCalledWith(mockSubscription.id);
|
|
394
|
-
expect(mockStripe.subscriptionItems.createUsageRecord).toHaveBeenCalledWith(subscriptionItem === null || subscriptionItem === void 0 ? void 0 : subscriptionItem.id, {
|
|
395
|
-
quantity: quantity,
|
|
396
|
-
});
|
|
397
|
-
});
|
|
398
|
-
it("should handle non-existent subscription", async () => {
|
|
399
|
-
const subscriptionId = "sub_nonexistent";
|
|
400
|
-
mockStripe.subscriptions.retrieve =
|
|
401
|
-
getJestMockFunction().mockResolvedValue(null);
|
|
402
|
-
await expect(billingService.addOrUpdateMeteredPricingOnSubscription(subscriptionId, ActiveMonitoringMeteredPlan, quantity)).rejects.toThrow(Errors.BillingService.SUBSCRIPTION_NOT_FOUND);
|
|
403
|
-
});
|
|
404
|
-
});
|
|
405
|
-
describe("isPromoCodeValid", () => {
|
|
406
|
-
it("should throw if billing is not enabled", async () => {
|
|
407
|
-
billingService = await mockIsBillingEnabled(false);
|
|
408
|
-
await expect(billingService.isPromoCodeValid("INVALID_PROMO_CODE")).rejects.toThrow(Errors.BillingService.BILLING_NOT_ENABLED);
|
|
409
|
-
});
|
|
410
|
-
it("should return true for a valid promo code", async () => {
|
|
411
|
-
const promoCode = "VALIDPROMO";
|
|
412
|
-
const mockCoupon = { valid: true };
|
|
413
|
-
mockStripe.coupons.retrieve =
|
|
414
|
-
getJestMockFunction().mockResolvedValue(mockCoupon);
|
|
415
|
-
const isValid = await billingService.isPromoCodeValid(promoCode);
|
|
416
|
-
expect(isValid).toBeTruthy();
|
|
417
|
-
expect(mockStripe.coupons.retrieve).toHaveBeenCalledWith(promoCode);
|
|
418
|
-
});
|
|
419
|
-
it("should return false for an invalid or expired promo code", async () => {
|
|
420
|
-
const promoCode = "INVALIDPROMO";
|
|
421
|
-
const mockCoupon = {
|
|
422
|
-
valid: false,
|
|
423
|
-
};
|
|
424
|
-
mockStripe.coupons.retrieve =
|
|
425
|
-
getJestMockFunction().mockResolvedValue(mockCoupon);
|
|
426
|
-
const isValid = await billingService.isPromoCodeValid(promoCode);
|
|
427
|
-
expect(isValid).toBeFalsy();
|
|
428
|
-
expect(mockStripe.coupons.retrieve).toHaveBeenCalledWith(promoCode);
|
|
429
|
-
});
|
|
430
|
-
it("should handle non-existent promo code", async () => {
|
|
431
|
-
const promoCode = "NONEXISTENTPROMO";
|
|
432
|
-
mockStripe.coupons.retrieve =
|
|
433
|
-
getJestMockFunction().mockResolvedValue(null);
|
|
434
|
-
await expect(billingService.isPromoCodeValid(promoCode)).rejects.toThrow(Errors.BillingService.PROMO_CODE_NOT_FOUND);
|
|
435
|
-
expect(mockStripe.coupons.retrieve).toHaveBeenCalledWith(promoCode);
|
|
436
|
-
});
|
|
437
|
-
it("should handle errors from the Stripe API", async () => {
|
|
438
|
-
const promoCode = "ERRORPROMO";
|
|
439
|
-
mockStripe.coupons.retrieve = getJestMockFunction().mockImplementation(() => {
|
|
440
|
-
throw new Error();
|
|
441
|
-
});
|
|
442
|
-
await expect(billingService.isPromoCodeValid(promoCode)).rejects.toThrow(Errors.BillingService.PROMO_CODE_INVALID);
|
|
443
|
-
});
|
|
444
|
-
});
|
|
445
|
-
describe("removeSubscriptionItem", () => {
|
|
446
|
-
const subscriptionId = "sub_123";
|
|
447
|
-
const subscriptionItemId = "si_123";
|
|
448
|
-
const isMeteredSubscriptionItem = false;
|
|
449
|
-
it("should throw if billing is not enabled", async () => {
|
|
450
|
-
billingService = await mockIsBillingEnabled(false);
|
|
451
|
-
await expect(billingService.removeSubscriptionItem(subscriptionId, subscriptionItemId, isMeteredSubscriptionItem)).rejects.toThrow(Errors.BillingService.BILLING_NOT_ENABLED);
|
|
452
|
-
});
|
|
453
|
-
it("should successfully remove a metered subscription item", async () => {
|
|
454
|
-
const isMeteredSubscriptionItem = true;
|
|
455
|
-
mockStripe.subscriptions.retrieve =
|
|
456
|
-
getJestMockFunction().mockResolvedValue(mockSubscription);
|
|
457
|
-
mockStripe.subscriptionItems.del =
|
|
458
|
-
getJestMockFunction().mockResolvedValue({});
|
|
459
|
-
await billingService.removeSubscriptionItem(subscriptionId, subscriptionItemId, isMeteredSubscriptionItem);
|
|
460
|
-
expect(mockStripe.subscriptionItems.del).toHaveBeenCalledWith(subscriptionItemId, {
|
|
461
|
-
proration_behavior: "create_prorations",
|
|
462
|
-
clear_usage: true,
|
|
463
|
-
});
|
|
464
|
-
});
|
|
465
|
-
it("should successfully remove a metered subscription item when isMeteredSubscriptionItem", async () => {
|
|
466
|
-
var _a;
|
|
467
|
-
const subscriptionItemId = ((_a = mockSubscription.items.data[0]) === null || _a === void 0 ? void 0 : _a.id) || "";
|
|
468
|
-
mockStripe.subscriptions.retrieve =
|
|
469
|
-
getJestMockFunction().mockResolvedValue(mockSubscription);
|
|
470
|
-
mockStripe.subscriptionItems.del =
|
|
471
|
-
getJestMockFunction().mockResolvedValue({});
|
|
472
|
-
await billingService.removeSubscriptionItem(mockSubscription.id, subscriptionItemId, isMeteredSubscriptionItem);
|
|
473
|
-
expect(mockStripe.subscriptionItems.del).toHaveBeenCalledWith(subscriptionItemId, {});
|
|
474
|
-
});
|
|
475
|
-
it("should handle non-existent subscription or subscription item", async () => {
|
|
476
|
-
mockStripe.subscriptions.retrieve =
|
|
477
|
-
getJestMockFunction().mockResolvedValue(null);
|
|
478
|
-
await expect(billingService.removeSubscriptionItem(subscriptionId, subscriptionItemId, isMeteredSubscriptionItem)).rejects.toThrow(Errors.BillingService.SUBSCRIPTION_NOT_FOUND);
|
|
479
|
-
});
|
|
480
|
-
it("should handle errors from the Stripe API", async () => {
|
|
481
|
-
mockStripe.subscriptions.retrieve =
|
|
482
|
-
getJestMockFunction().mockResolvedValue(mockSubscription);
|
|
483
|
-
mockStripe.subscriptionItems.del =
|
|
484
|
-
getJestMockFunction().mockImplementation(() => {
|
|
485
|
-
throw new Error("Stripe API error");
|
|
486
|
-
});
|
|
487
|
-
await expect(billingService.removeSubscriptionItem(subscriptionId, subscriptionItemId, isMeteredSubscriptionItem)).rejects.toThrow("Stripe API error");
|
|
488
|
-
});
|
|
489
|
-
it("should not remove an item if the subscription is canceled", async () => {
|
|
490
|
-
const isMeteredSubscriptionItem = false;
|
|
491
|
-
mockSubscription.status = "canceled";
|
|
492
|
-
mockStripe.subscriptions.retrieve =
|
|
493
|
-
getJestMockFunction().mockResolvedValue(mockSubscription);
|
|
494
|
-
mockStripe.subscriptionItems.del = getJestMockFunction();
|
|
495
|
-
await billingService.removeSubscriptionItem(subscriptionId, subscriptionItemId, isMeteredSubscriptionItem);
|
|
496
|
-
expect(mockStripe.subscriptions.del).not.toHaveBeenCalled();
|
|
497
|
-
});
|
|
498
|
-
});
|
|
499
|
-
describe("getSubscriptionItems", () => {
|
|
500
|
-
it("should throw if billing is not enabled", async () => {
|
|
501
|
-
billingService = await mockIsBillingEnabled(false);
|
|
502
|
-
await expect(billingService.getSubscriptionItems(mockSubscription.id)).rejects.toThrow(Errors.BillingService.BILLING_NOT_ENABLED);
|
|
503
|
-
});
|
|
504
|
-
it("should successfully retrieve subscription items for a given subscription", async () => {
|
|
505
|
-
mockSubscription.items.data = [
|
|
506
|
-
// @ts-expect-error - Simplified mock object for testing without all required Stripe SubscriptionItem properties
|
|
507
|
-
{ id: "item_1", price: { id: "price_123" } },
|
|
508
|
-
// @ts-expect-error - Simplified mock object for testing without all required Stripe SubscriptionItem properties
|
|
509
|
-
{ id: "item_2", price: { id: "price_456" } },
|
|
510
|
-
];
|
|
511
|
-
mockStripe.subscriptions.retrieve =
|
|
512
|
-
getJestMockFunction().mockResolvedValue(mockSubscription);
|
|
513
|
-
const items = await billingService.getSubscriptionItems(mockSubscription.id);
|
|
514
|
-
expect(items).toEqual(mockSubscription.items.data);
|
|
515
|
-
expect(mockStripe.subscriptions.retrieve).toHaveBeenCalledWith(mockSubscription.id);
|
|
516
|
-
});
|
|
517
|
-
it("should handle the case where the subscription does not exist", async () => {
|
|
518
|
-
const subscriptionId = "sub_nonexistent";
|
|
519
|
-
mockStripe.subscriptions.retrieve =
|
|
520
|
-
getJestMockFunction().mockResolvedValue(null);
|
|
521
|
-
await expect(billingService.getSubscriptionItems(subscriptionId)).rejects.toThrow(Errors.BillingService.SUBSCRIPTION_NOT_FOUND);
|
|
522
|
-
});
|
|
523
|
-
});
|
|
524
|
-
});
|
|
525
|
-
describe("Payment & Billing", () => {
|
|
526
|
-
const customerId = "cust_123";
|
|
527
|
-
const invoiceId = "inv_123";
|
|
528
|
-
const paymentMethodId = "pm_123";
|
|
529
|
-
const subscriptionId = "sub_123";
|
|
530
|
-
const mockPaymentMethods = [
|
|
531
|
-
{
|
|
532
|
-
id: "pm_123",
|
|
533
|
-
type: "card",
|
|
534
|
-
last4Digits: "4242",
|
|
535
|
-
isDefault: true,
|
|
536
|
-
},
|
|
537
|
-
{
|
|
538
|
-
id: "pm_456",
|
|
539
|
-
type: "card",
|
|
540
|
-
last4Digits: "4343",
|
|
541
|
-
isDefault: false,
|
|
542
|
-
},
|
|
543
|
-
];
|
|
544
|
-
describe("generateCouponCode", () => {
|
|
545
|
-
const couponData = getCouponData();
|
|
546
|
-
const mockCoupon = {
|
|
547
|
-
id: "coupon_123",
|
|
548
|
-
valid: true,
|
|
549
|
-
};
|
|
550
|
-
it("should successfully generate a coupon code", async () => {
|
|
551
|
-
mockStripe.coupons.create =
|
|
552
|
-
getJestMockFunction().mockResolvedValue(mockCoupon);
|
|
553
|
-
const result = await billingService.generateCouponCode(couponData);
|
|
554
|
-
expect(result).toEqual(mockCoupon.id);
|
|
555
|
-
expect(mockStripe.coupons.create).toHaveBeenCalledWith(expect.objectContaining({
|
|
556
|
-
name: couponData.name,
|
|
557
|
-
percent_off: couponData.percentOff,
|
|
558
|
-
duration: "repeating",
|
|
559
|
-
duration_in_months: couponData.durationInMonths,
|
|
560
|
-
max_redemptions: couponData.maxRedemptions,
|
|
561
|
-
metadata: couponData.metadata,
|
|
562
|
-
}));
|
|
563
|
-
});
|
|
564
|
-
});
|
|
565
|
-
describe("deletePaymentMethod", () => {
|
|
566
|
-
it("should throw if billing is not enabled", async () => {
|
|
567
|
-
billingService = await mockIsBillingEnabled(false);
|
|
568
|
-
await expect(billingService.deletePaymentMethod(customerId, paymentMethodId)).rejects.toThrow(Errors.BillingService.BILLING_NOT_ENABLED);
|
|
569
|
-
});
|
|
570
|
-
it("should successfully delete a payment method", async () => {
|
|
571
|
-
billingService.getPaymentMethods =
|
|
572
|
-
getJestMockFunction().mockResolvedValue(mockPaymentMethods);
|
|
573
|
-
mockStripe.paymentMethods.detach =
|
|
574
|
-
getJestMockFunction().mockResolvedValue({});
|
|
575
|
-
await billingService.deletePaymentMethod(customerId, paymentMethodId);
|
|
576
|
-
expect(mockStripe.paymentMethods.detach).toHaveBeenCalledWith(paymentMethodId);
|
|
577
|
-
});
|
|
578
|
-
it("should throw an exception if it's the only payment method", async () => {
|
|
579
|
-
// mock a single payment method to simulate a scenario where deletion is not allowed
|
|
580
|
-
const mockSinglePaymentMethod = [
|
|
581
|
-
{
|
|
582
|
-
id: paymentMethodId,
|
|
583
|
-
type: "card",
|
|
584
|
-
last4Digits: "4242",
|
|
585
|
-
isDefault: true,
|
|
586
|
-
},
|
|
587
|
-
];
|
|
588
|
-
billingService.getPaymentMethods =
|
|
589
|
-
getJestMockFunction().mockResolvedValue(mockSinglePaymentMethod);
|
|
590
|
-
await expect(billingService.deletePaymentMethod(customerId, paymentMethodId)).rejects.toThrow(Errors.BillingService.MIN_REQUIRED_PAYMENT_METHOD_NOT_MET);
|
|
591
|
-
});
|
|
592
|
-
});
|
|
593
|
-
describe("hasPaymentMethods", () => {
|
|
594
|
-
it("should return true if the customer has payment methods", async () => {
|
|
595
|
-
billingService.getPaymentMethods =
|
|
596
|
-
getJestMockFunction().mockResolvedValue(mockPaymentMethods);
|
|
597
|
-
const result = await billingService.hasPaymentMethods(customerId);
|
|
598
|
-
expect(result).toBeTruthy();
|
|
599
|
-
expect(billingService.getPaymentMethods).toHaveBeenCalledWith(customerId);
|
|
600
|
-
});
|
|
601
|
-
it("should return false if the customer does not have payment methods", async () => {
|
|
602
|
-
const mockEmptyPaymentMethods = Array();
|
|
603
|
-
billingService.getPaymentMethods =
|
|
604
|
-
getJestMockFunction().mockResolvedValue(mockEmptyPaymentMethods);
|
|
605
|
-
const result = await billingService.hasPaymentMethods(customerId);
|
|
606
|
-
expect(result).toBeFalsy();
|
|
607
|
-
expect(billingService.getPaymentMethods).toHaveBeenCalledWith(customerId);
|
|
608
|
-
});
|
|
609
|
-
});
|
|
610
|
-
describe("getPaymentMethods", () => {
|
|
611
|
-
it("should throw if billing is not enabled", async () => {
|
|
612
|
-
billingService = await mockIsBillingEnabled(false);
|
|
613
|
-
await expect(billingService.getPaymentMethods(customerId)).rejects.toThrow(Errors.BillingService.BILLING_NOT_ENABLED);
|
|
614
|
-
});
|
|
615
|
-
it("should return all payment methods for a customer", async () => {
|
|
616
|
-
var _a, _b;
|
|
617
|
-
const mockPaymentMethodsResponse = {
|
|
618
|
-
data: [
|
|
619
|
-
{
|
|
620
|
-
id: "pm_123",
|
|
621
|
-
type: "card",
|
|
622
|
-
// @ts-expect-error - Simplified mock card object for testing without all required Stripe card properties
|
|
623
|
-
card: { last4: "4242", brand: "mastercard" },
|
|
624
|
-
isDefault: true,
|
|
625
|
-
},
|
|
626
|
-
{
|
|
627
|
-
id: "pm_456",
|
|
628
|
-
type: "card",
|
|
629
|
-
// @ts-expect-error - Simplified mock card object for testing without all required Stripe card properties
|
|
630
|
-
card: { last4: "4343", brand: "mastercard" },
|
|
631
|
-
isDefault: true,
|
|
632
|
-
},
|
|
633
|
-
],
|
|
634
|
-
};
|
|
635
|
-
mockStripe.paymentMethods.list = getJestMockFunction()
|
|
636
|
-
.mockResolvedValueOnce(mockPaymentMethodsResponse)
|
|
637
|
-
.mockResolvedValue({ data: [] });
|
|
638
|
-
mockStripe.customers.retrieve =
|
|
639
|
-
getJestMockFunction().mockResolvedValue(mockCustomer);
|
|
640
|
-
const paymentMethods = await billingService.getPaymentMethods(customerId);
|
|
641
|
-
expect(paymentMethods).toHaveLength(2);
|
|
642
|
-
expect((_a = paymentMethods[0]) === null || _a === void 0 ? void 0 : _a.id).toBe("pm_123");
|
|
643
|
-
expect((_b = paymentMethods[0]) === null || _b === void 0 ? void 0 : _b.last4Digits).toBe("4242");
|
|
644
|
-
expect(mockStripe.paymentMethods.list).toHaveBeenCalledWith({
|
|
645
|
-
customer: customerId,
|
|
646
|
-
type: "card",
|
|
647
|
-
});
|
|
648
|
-
});
|
|
649
|
-
it("should return an empty array if no payment methods are present", async () => {
|
|
650
|
-
const mockEmptyPaymentMethodsResponse = { data: [] };
|
|
651
|
-
mockStripe.paymentMethods.list =
|
|
652
|
-
getJestMockFunction().mockResolvedValue(mockEmptyPaymentMethodsResponse);
|
|
653
|
-
mockStripe.customers.retrieve =
|
|
654
|
-
getJestMockFunction().mockResolvedValue(mockCustomer);
|
|
655
|
-
const paymentMethods = await billingService.getPaymentMethods(customerId);
|
|
656
|
-
expect(paymentMethods).toEqual([]);
|
|
657
|
-
expect(mockStripe.paymentMethods.list).toHaveBeenCalledWith({
|
|
658
|
-
customer: customerId,
|
|
659
|
-
type: "card",
|
|
660
|
-
});
|
|
661
|
-
});
|
|
662
|
-
});
|
|
663
|
-
describe("getSetupIntentSecret", () => {
|
|
664
|
-
it("should successfully return a setup intent secret", async () => {
|
|
665
|
-
const mockSetupIntent = {
|
|
666
|
-
client_secret: "seti_123_secret_xyz",
|
|
667
|
-
};
|
|
668
|
-
mockStripe.setupIntents.create =
|
|
669
|
-
getJestMockFunction().mockResolvedValue(mockSetupIntent);
|
|
670
|
-
const secret = await billingService.getSetupIntentSecret(customerId);
|
|
671
|
-
expect(secret).toBe(mockSetupIntent.client_secret);
|
|
672
|
-
expect(mockStripe.setupIntents.create).toHaveBeenCalledWith({
|
|
673
|
-
customer: customerId,
|
|
674
|
-
});
|
|
675
|
-
});
|
|
676
|
-
it("should handle missing client secret in the response", async () => {
|
|
677
|
-
mockStripe.setupIntents.create =
|
|
678
|
-
getJestMockFunction().mockResolvedValue({});
|
|
679
|
-
await expect(billingService.getSetupIntentSecret(customerId)).rejects.toThrow(Errors.BillingService.CLIENT_SECRET_MISSING);
|
|
680
|
-
});
|
|
681
|
-
});
|
|
682
|
-
describe("cancelSubscription", () => {
|
|
683
|
-
it("should successfully cancel a subscription", async () => {
|
|
684
|
-
mockStripe.subscriptions.del = getJestMockFunction().mockResolvedValue({
|
|
685
|
-
id: subscriptionId,
|
|
686
|
-
status: "canceled",
|
|
687
|
-
});
|
|
688
|
-
await billingService.cancelSubscription(subscriptionId);
|
|
689
|
-
expect(mockStripe.subscriptions.del).toHaveBeenCalledWith(subscriptionId);
|
|
690
|
-
});
|
|
691
|
-
it("should handle errors from the Stripe API", async () => {
|
|
692
|
-
const subscriptionId = "sub_123";
|
|
693
|
-
// mock an error response from the Stripe API
|
|
694
|
-
mockStripe.subscriptions.del = getJestMockFunction().mockImplementation(() => {
|
|
695
|
-
throw new Error("Stripe API error");
|
|
696
|
-
});
|
|
697
|
-
await billingService.cancelSubscription(subscriptionId);
|
|
698
|
-
// todo: we could expect the error to be logged
|
|
699
|
-
});
|
|
700
|
-
it("should not cancel a subscription if billing is not enabled", async () => {
|
|
701
|
-
const subscriptionId = "sub_123";
|
|
702
|
-
billingService = await mockIsBillingEnabled(false);
|
|
703
|
-
await expect(billingService.cancelSubscription(subscriptionId)).rejects.toThrow(Errors.BillingService.BILLING_NOT_ENABLED);
|
|
704
|
-
expect(mockStripe.subscriptions.del).not.toHaveBeenCalled();
|
|
705
|
-
});
|
|
706
|
-
});
|
|
707
|
-
describe("getSubscriptionStatus", () => {
|
|
708
|
-
const expectedStatus = SubscriptionStatus.Active;
|
|
709
|
-
it("should successfully retrieve the subscription status", async () => {
|
|
710
|
-
mockStripe.subscriptions.retrieve =
|
|
711
|
-
getJestMockFunction().mockResolvedValue({
|
|
712
|
-
id: subscriptionId,
|
|
713
|
-
status: expectedStatus,
|
|
714
|
-
});
|
|
715
|
-
const status = await billingService.getSubscriptionStatus(subscriptionId);
|
|
716
|
-
expect(status).toBe(expectedStatus);
|
|
717
|
-
expect(mockStripe.subscriptions.retrieve).toHaveBeenCalledWith(subscriptionId);
|
|
718
|
-
});
|
|
719
|
-
it("should successfully retrieve the subscription status", async () => {
|
|
720
|
-
mockStripe.subscriptions.retrieve =
|
|
721
|
-
getJestMockFunction().mockResolvedValue({
|
|
722
|
-
id: subscriptionId,
|
|
723
|
-
status: expectedStatus,
|
|
724
|
-
});
|
|
725
|
-
const status = await billingService.getSubscriptionStatus(subscriptionId);
|
|
726
|
-
expect(status).toBe(expectedStatus);
|
|
727
|
-
expect(mockStripe.subscriptions.retrieve).toHaveBeenCalledWith(subscriptionId);
|
|
728
|
-
});
|
|
729
|
-
});
|
|
730
|
-
describe("getSubscription", () => {
|
|
731
|
-
it("should throw if billing is not enabled", async () => {
|
|
732
|
-
billingService = await mockIsBillingEnabled(false);
|
|
733
|
-
await expect(billingService.getSubscription(subscriptionId)).rejects.toThrow(Errors.BillingService.BILLING_NOT_ENABLED);
|
|
734
|
-
});
|
|
735
|
-
it("should successfully retrieve subscription data", async () => {
|
|
736
|
-
const subscriptionId = "sub_123";
|
|
737
|
-
const mockSubscription = getStripeSubscription();
|
|
738
|
-
mockStripe.subscriptions.retrieve =
|
|
739
|
-
getJestMockFunction().mockResolvedValue(mockSubscription);
|
|
740
|
-
const subscription = await billingService.getSubscription(subscriptionId);
|
|
741
|
-
expect(subscription).toEqual(mockSubscription);
|
|
742
|
-
expect(mockStripe.subscriptions.retrieve).toHaveBeenCalledWith(subscriptionId);
|
|
743
|
-
});
|
|
744
|
-
});
|
|
745
|
-
describe("getInvoices", () => {
|
|
746
|
-
it("should successfully retrieve a list of invoices for a customer", async () => {
|
|
747
|
-
const mockInvoices = {
|
|
748
|
-
data: [getStripeInvoice(), getStripeInvoice()],
|
|
749
|
-
};
|
|
750
|
-
mockStripe.invoices.list =
|
|
751
|
-
getJestMockFunction().mockResolvedValue(mockInvoices);
|
|
752
|
-
const invoices = await billingService.getInvoices(customerId);
|
|
753
|
-
expect(invoices).toEqual(mockInvoices.data.map((invoice) => {
|
|
754
|
-
return {
|
|
755
|
-
id: invoice.id,
|
|
756
|
-
amount: invoice.amount_due,
|
|
757
|
-
currencyCode: invoice.currency,
|
|
758
|
-
customerId: invoice.customer,
|
|
759
|
-
downloadableLink: "",
|
|
760
|
-
status: "paid",
|
|
761
|
-
subscriptionId: invoice.subscription,
|
|
762
|
-
invoiceNumber: invoice.number,
|
|
763
|
-
invoiceDate: new Date(invoice.created * 1000),
|
|
764
|
-
};
|
|
765
|
-
}));
|
|
766
|
-
expect(mockStripe.invoices.list).toHaveBeenCalledWith({
|
|
767
|
-
customer: customerId,
|
|
768
|
-
limit: 100,
|
|
769
|
-
});
|
|
770
|
-
});
|
|
771
|
-
it("should return an empty array if no invoices are found for the customer", async () => {
|
|
772
|
-
const mockEmptyInvoices = { data: [] };
|
|
773
|
-
mockStripe.invoices.list =
|
|
774
|
-
getJestMockFunction().mockResolvedValue(mockEmptyInvoices);
|
|
775
|
-
const invoices = await billingService.getInvoices(customerId);
|
|
776
|
-
expect(invoices).toEqual([]);
|
|
777
|
-
expect(mockStripe.invoices.list).toHaveBeenCalledWith({
|
|
778
|
-
customer: customerId,
|
|
779
|
-
limit: 100,
|
|
780
|
-
});
|
|
781
|
-
});
|
|
782
|
-
});
|
|
783
|
-
describe("generateInvoiceAndChargeCustomer", () => {
|
|
784
|
-
const itemText = "Service Charge";
|
|
785
|
-
const amountInUsd = 100;
|
|
786
|
-
const mockPaymentMethodsResponse = {
|
|
787
|
-
data: [
|
|
788
|
-
{
|
|
789
|
-
id: "pm_123",
|
|
790
|
-
type: "card",
|
|
791
|
-
last4Digits: "4242",
|
|
792
|
-
isDefault: true,
|
|
793
|
-
},
|
|
794
|
-
],
|
|
795
|
-
};
|
|
796
|
-
it("should successfully generate an invoice and charge the customer", async () => {
|
|
797
|
-
var _a;
|
|
798
|
-
mockStripe.paymentMethods.list = getJestMockFunction()
|
|
799
|
-
.mockResolvedValueOnce(mockPaymentMethodsResponse)
|
|
800
|
-
.mockResolvedValue({ data: [] });
|
|
801
|
-
mockStripe.customers.retrieve =
|
|
802
|
-
getJestMockFunction().mockResolvedValue(mockCustomer);
|
|
803
|
-
// mock responses for invoice creation, adding an item, and finalizing
|
|
804
|
-
const mockInvoice = getStripeInvoice();
|
|
805
|
-
mockStripe.invoices.create =
|
|
806
|
-
getJestMockFunction().mockResolvedValue(mockInvoice);
|
|
807
|
-
mockStripe.invoiceItems.create =
|
|
808
|
-
getJestMockFunction().mockResolvedValue({});
|
|
809
|
-
mockStripe.invoices.finalizeInvoice =
|
|
810
|
-
getJestMockFunction().mockResolvedValue({});
|
|
811
|
-
// mock response for paying the invoice
|
|
812
|
-
mockStripe.invoices.pay = getJestMockFunction().mockResolvedValue({});
|
|
813
|
-
await billingService.generateInvoiceAndChargeCustomer(customerId, itemText, amountInUsd);
|
|
814
|
-
expect(mockStripe.invoices.create).toHaveBeenCalledWith(expect.objectContaining({ customer: customerId }));
|
|
815
|
-
expect(mockStripe.invoiceItems.create).toHaveBeenCalledWith(expect.objectContaining({ invoice: mockInvoice.id }));
|
|
816
|
-
expect(mockStripe.invoices.finalizeInvoice).toHaveBeenCalledWith(mockInvoice.id);
|
|
817
|
-
expect(mockStripe.invoices.pay).toHaveBeenCalledWith(mockInvoice.id, {
|
|
818
|
-
payment_method: (_a = mockPaymentMethodsResponse.data[0]) === null || _a === void 0 ? void 0 : _a.id,
|
|
819
|
-
});
|
|
820
|
-
});
|
|
821
|
-
it("should handle payment method errors when creating the invoice", async () => {
|
|
822
|
-
mockStripe.invoices.create =
|
|
823
|
-
getJestMockFunction().mockResolvedValue(null);
|
|
824
|
-
await expect(billingService.generateInvoiceAndChargeCustomer(customerId, itemText, amountInUsd)).rejects.toThrow(Errors.BillingService.INVOICE_NOT_GENERATED);
|
|
825
|
-
});
|
|
826
|
-
it("should handle payment method errors when charging the invoice", async () => {
|
|
827
|
-
mockStripe.paymentMethods.list = getJestMockFunction()
|
|
828
|
-
.mockResolvedValueOnce(mockPaymentMethodsResponse)
|
|
829
|
-
.mockResolvedValue({ data: [] });
|
|
830
|
-
mockStripe.customers.retrieve =
|
|
831
|
-
getJestMockFunction().mockResolvedValue(mockCustomer);
|
|
832
|
-
// mock successful invoice creation and finalization
|
|
833
|
-
const mockInvoice = getStripeInvoice();
|
|
834
|
-
mockStripe.invoices.create =
|
|
835
|
-
getJestMockFunction().mockResolvedValue(mockInvoice);
|
|
836
|
-
mockStripe.invoiceItems.create =
|
|
837
|
-
getJestMockFunction().mockResolvedValue({});
|
|
838
|
-
mockStripe.invoices.finalizeInvoice =
|
|
839
|
-
getJestMockFunction().mockResolvedValue({});
|
|
840
|
-
billingService.voidInvoice = getJestMockFunction();
|
|
841
|
-
// mock an error during invoice payment
|
|
842
|
-
mockStripe.invoices.pay = getJestMockFunction().mockImplementation(() => {
|
|
843
|
-
throw new Error("Payment method error");
|
|
844
|
-
});
|
|
845
|
-
await expect(billingService.generateInvoiceAndChargeCustomer(customerId, itemText, amountInUsd)).rejects.toThrow();
|
|
846
|
-
expect(billingService.voidInvoice).toHaveBeenCalled();
|
|
847
|
-
});
|
|
848
|
-
});
|
|
849
|
-
describe("voidInvoice", () => {
|
|
850
|
-
it("should successfully void an invoice", async () => {
|
|
851
|
-
const mockVoidedInvoice = getStripeInvoice();
|
|
852
|
-
mockVoidedInvoice.status = "void";
|
|
853
|
-
mockStripe.invoices.voidInvoice =
|
|
854
|
-
getJestMockFunction().mockResolvedValue(mockVoidedInvoice);
|
|
855
|
-
const voidedInvoice = await billingService.voidInvoice(invoiceId);
|
|
856
|
-
expect(voidedInvoice).toEqual(mockVoidedInvoice);
|
|
857
|
-
expect(mockStripe.invoices.voidInvoice).toHaveBeenCalledWith(invoiceId);
|
|
858
|
-
});
|
|
859
|
-
});
|
|
860
|
-
describe("payInvoice", () => {
|
|
861
|
-
const mockPaymentMethodsResponse = {
|
|
862
|
-
data: [
|
|
863
|
-
{
|
|
864
|
-
id: "pm_123",
|
|
865
|
-
type: "card",
|
|
866
|
-
last4Digits: "4242",
|
|
867
|
-
isDefault: true,
|
|
868
|
-
},
|
|
869
|
-
],
|
|
870
|
-
};
|
|
871
|
-
it("should throw if billing is not enabled", async () => {
|
|
872
|
-
billingService = await mockIsBillingEnabled(false);
|
|
873
|
-
await expect(billingService.payInvoice(customerId, invoiceId)).rejects.toThrow(Errors.BillingService.BILLING_NOT_ENABLED);
|
|
874
|
-
});
|
|
875
|
-
it("should throw if no payments methods exist", async () => {
|
|
876
|
-
mockStripe.paymentMethods.list =
|
|
877
|
-
getJestMockFunction().mockResolvedValue({ data: [] });
|
|
878
|
-
mockStripe.customers.retrieve =
|
|
879
|
-
getJestMockFunction().mockResolvedValue(mockCustomer);
|
|
880
|
-
await expect(billingService.payInvoice(customerId, invoiceId)).rejects.toThrow(Errors.BillingService.NO_PAYMENTS_METHODS);
|
|
881
|
-
});
|
|
882
|
-
it("should successfully pay an invoice", async () => {
|
|
883
|
-
mockStripe.paymentMethods.list = getJestMockFunction()
|
|
884
|
-
.mockResolvedValueOnce(mockPaymentMethodsResponse)
|
|
885
|
-
.mockResolvedValue({ data: [] });
|
|
886
|
-
mockStripe.customers.retrieve =
|
|
887
|
-
getJestMockFunction().mockResolvedValue(mockCustomer);
|
|
888
|
-
const mockPaidInvoice = getStripeInvoice();
|
|
889
|
-
mockStripe.invoices.pay =
|
|
890
|
-
getJestMockFunction().mockResolvedValue(mockPaidInvoice);
|
|
891
|
-
const paidInvoice = await billingService.payInvoice(customerId, mockPaidInvoice.id || "");
|
|
892
|
-
expect(paidInvoice).toEqual({
|
|
893
|
-
id: mockPaidInvoice.id,
|
|
894
|
-
amount: mockPaidInvoice.amount_due,
|
|
895
|
-
currencyCode: mockPaidInvoice.currency,
|
|
896
|
-
customerId: mockPaidInvoice.customer,
|
|
897
|
-
status: mockPaidInvoice.status,
|
|
898
|
-
downloadableLink: "",
|
|
899
|
-
subscriptionId: mockPaidInvoice.subscription,
|
|
900
|
-
invoiceNumber: mockPaidInvoice.number,
|
|
901
|
-
invoiceDate: new Date(mockPaidInvoice.created * 1000),
|
|
902
|
-
});
|
|
903
|
-
expect(mockStripe.invoices.pay).toHaveBeenCalledWith(mockPaidInvoice.id, {
|
|
904
|
-
payment_method: paymentMethodId,
|
|
905
|
-
});
|
|
906
|
-
});
|
|
907
|
-
});
|
|
908
|
-
});
|
|
909
|
-
});
|
|
910
|
-
//# sourceMappingURL=BillingService.test.js.map
|