Skip to content

Commit 996e8f2

Browse files
henrybarretogustavosbarreto
authored andcommitted
feat(api): check for cloud and billing to perform billing device limits
1 parent 447887c commit 996e8f2

File tree

2 files changed

+70
-69
lines changed

2 files changed

+70
-69
lines changed

api/services/device.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ func (s *service) UpdateDeviceStatus(ctx context.Context, tenant string, uid mod
333333
isRemoved := false
334334

335335
switch {
336-
case envs.IsCloud():
336+
case envs.IsCloud() && envs.HasBilling():
337337
if namespace.Billing.IsActive() {
338338
if err := s.BillingReport(s.client, namespace.TenantID, ReportDeviceAccept); err != nil {
339339
return NewErrBillingReportNamespaceDelete(err)
@@ -370,7 +370,7 @@ func (s *service) UpdateDeviceStatus(ctx context.Context, tenant string, uid mod
370370
return ErrDeviceLimit
371371
}
372372
}
373-
case envs.IsCommunity(), envs.IsEnterprise():
373+
default:
374374
if namespace.HasMaxDevices() && namespace.HasMaxDevicesReached() {
375375
return NewErrDeviceMaxDevicesReached(namespace.MaxDevices)
376376
}

api/services/device_test.go

Lines changed: 68 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -2330,7 +2330,7 @@ func TestUpdateDeviceStatus_community_and_enterprise(t *testing.T) {
23302330
envMock.
23312331
On("Get", "SHELLHUB_CLOUD").
23322332
Return("false").
2333-
Twice()
2333+
Once()
23342334
envMock.
23352335
On("Get", "SHELLHUB_ENTERPRISE").
23362336
Return("false").
@@ -2398,7 +2398,7 @@ func TestUpdateDeviceStatus_community_and_enterprise(t *testing.T) {
23982398
envMock.
23992399
On("Get", "SHELLHUB_CLOUD").
24002400
Return("false").
2401-
Twice()
2401+
Once()
24022402
envMock.
24032403
On("Get", "SHELLHUB_ENTERPRISE").
24042404
Return("false").
@@ -2469,7 +2469,7 @@ func TestUpdateDeviceStatus_community_and_enterprise(t *testing.T) {
24692469
Once()
24702470
envMock.
24712471
On("Get", "SHELLHUB_CLOUD").
2472-
Return("false").Twice()
2472+
Return("false").Once()
24732473
envMock.
24742474
On("Get", "SHELLHUB_ENTERPRISE").
24752475
Return("false").Once()
@@ -2703,12 +2703,13 @@ func TestUpdateDeviceStatus_cloud_subscription_active(t *testing.T) {
27032703
Return(nil, store.ErrNoDocuments).
27042704
Once()
27052705
envMock.
2706-
On("Get", "SHELLHUB_CLOUD").
2706+
On("Get", "SHELLHUB_BILLING").
27072707
Return("true").
2708-
Twice()
2708+
Once()
27092709
envMock.
2710-
On("Get", "SHELLHUB_ENTERPRISE").
2711-
Return("false").Once()
2710+
On("Get", "SHELLHUB_CLOUD").
2711+
Return("true").
2712+
Once()
27122713
clientMock.
27132714
On("BillingReport", "00000000-0000-0000-0000-000000000000", "device_accept").
27142715
Return(0, errors.New("error", "", 0)).
@@ -2777,12 +2778,12 @@ func TestUpdateDeviceStatus_cloud_subscription_active(t *testing.T) {
27772778
Return(nil, store.ErrNoDocuments).
27782779
Once()
27792780
envMock.
2780-
On("Get", "SHELLHUB_CLOUD").
2781+
On("Get", "SHELLHUB_BILLING").
27812782
Return("true").
2782-
Twice()
2783+
Once()
27832784
envMock.
2784-
On("Get", "SHELLHUB_ENTERPRISE").
2785-
Return("false").
2785+
On("Get", "SHELLHUB_CLOUD").
2786+
Return("true").
27862787
Once()
27872788
clientMock.
27882789
On("BillingReport", "00000000-0000-0000-0000-000000000000", "device_accept").
@@ -2852,12 +2853,12 @@ func TestUpdateDeviceStatus_cloud_subscription_active(t *testing.T) {
28522853
Return(nil, store.ErrNoDocuments).
28532854
Once()
28542855
envMock.
2855-
On("Get", "SHELLHUB_CLOUD").
2856+
On("Get", "SHELLHUB_BILLING").
28562857
Return("true").
2857-
Twice()
2858+
Once()
28582859
envMock.
2859-
On("Get", "SHELLHUB_ENTERPRISE").
2860-
Return("false").
2860+
On("Get", "SHELLHUB_CLOUD").
2861+
Return("true").
28612862
Once()
28622863
clientMock.
28632864
On("BillingReport", "00000000-0000-0000-0000-000000000000", "device_accept").
@@ -2931,12 +2932,12 @@ func TestUpdateDeviceStatus_cloud_subscription_active(t *testing.T) {
29312932
Return(nil, store.ErrNoDocuments).
29322933
Once()
29332934
envMock.
2934-
On("Get", "SHELLHUB_CLOUD").
2935+
On("Get", "SHELLHUB_BILLING").
29352936
Return("true").
2936-
Twice()
2937+
Once()
29372938
envMock.
2938-
On("Get", "SHELLHUB_ENTERPRISE").
2939-
Return("false").
2939+
On("Get", "SHELLHUB_CLOUD").
2940+
Return("true").
29402941
Once()
29412942
clientMock.
29422943
On("BillingReport", "00000000-0000-0000-0000-000000000000", "device_accept").
@@ -3168,12 +3169,12 @@ func TestUpdateDeviceStatus_cloud_subscription_inactive(t *testing.T) {
31683169
Return(nil, store.ErrNoDocuments).
31693170
Once()
31703171
envMock.
3171-
On("Get", "SHELLHUB_CLOUD").
3172+
On("Get", "SHELLHUB_BILLING").
31723173
Return("true").
3173-
Twice()
3174+
Once()
31743175
envMock.
3175-
On("Get", "SHELLHUB_ENTERPRISE").
3176-
Return("false").
3176+
On("Get", "SHELLHUB_CLOUD").
3177+
Return("true").
31773178
Once()
31783179
storeMock.
31793180
On("DeviceRemovedGet", ctx, "00000000-0000-0000-0000-000000000000", models.UID("uid")).
@@ -3240,12 +3241,12 @@ func TestUpdateDeviceStatus_cloud_subscription_inactive(t *testing.T) {
32403241
Return(nil, store.ErrNoDocuments).
32413242
Once()
32423243
envMock.
3243-
On("Get", "SHELLHUB_CLOUD").
3244+
On("Get", "SHELLHUB_BILLING").
32443245
Return("true").
3245-
Twice()
3246+
Once()
32463247
envMock.
3247-
On("Get", "SHELLHUB_ENTERPRISE").
3248-
Return("false").
3248+
On("Get", "SHELLHUB_CLOUD").
3249+
Return("true").
32493250
Once()
32503251
storeMock.
32513252
On("DeviceRemovedGet", ctx, "00000000-0000-0000-0000-000000000000", models.UID("uid")).
@@ -3321,12 +3322,12 @@ func TestUpdateDeviceStatus_cloud_subscription_inactive(t *testing.T) {
33213322
Return(nil, store.ErrNoDocuments).
33223323
Once()
33233324
envMock.
3324-
On("Get", "SHELLHUB_CLOUD").
3325+
On("Get", "SHELLHUB_BILLING").
33253326
Return("true").
3326-
Twice()
3327+
Once()
33273328
envMock.
3328-
On("Get", "SHELLHUB_ENTERPRISE").
3329-
Return("false").
3329+
On("Get", "SHELLHUB_CLOUD").
3330+
Return("true").
33303331
Once()
33313332
storeMock.
33323333
On("DeviceRemovedGet", ctx, "00000000-0000-0000-0000-000000000000", models.UID("uid")).
@@ -3397,12 +3398,12 @@ func TestUpdateDeviceStatus_cloud_subscription_inactive(t *testing.T) {
33973398
Return(nil, store.ErrNoDocuments).
33983399
Once()
33993400
envMock.
3400-
On("Get", "SHELLHUB_CLOUD").
3401+
On("Get", "SHELLHUB_BILLING").
34013402
Return("true").
3402-
Twice()
3403+
Once()
34033404
envMock.
3404-
On("Get", "SHELLHUB_ENTERPRISE").
3405-
Return("false").
3405+
On("Get", "SHELLHUB_CLOUD").
3406+
Return("true").
34063407
Once()
34073408
storeMock.
34083409
On("DeviceRemovedGet", ctx, "00000000-0000-0000-0000-000000000000", models.UID("uid")).
@@ -3477,12 +3478,12 @@ func TestUpdateDeviceStatus_cloud_subscription_inactive(t *testing.T) {
34773478
Return(nil, store.ErrNoDocuments).
34783479
Once()
34793480
envMock.
3480-
On("Get", "SHELLHUB_CLOUD").
3481+
On("Get", "SHELLHUB_BILLING").
34813482
Return("true").
3482-
Twice()
3483+
Once()
34833484
envMock.
3484-
On("Get", "SHELLHUB_ENTERPRISE").
3485-
Return("false").
3485+
On("Get", "SHELLHUB_CLOUD").
3486+
Return("true").
34863487
Once()
34873488
storeMock.
34883489
On("DeviceRemovedGet", ctx, "00000000-0000-0000-0000-000000000000", models.UID("uid")).
@@ -3563,12 +3564,12 @@ func TestUpdateDeviceStatus_cloud_subscription_inactive(t *testing.T) {
35633564
Return(nil, store.ErrNoDocuments).
35643565
Once()
35653566
envMock.
3566-
On("Get", "SHELLHUB_CLOUD").
3567+
On("Get", "SHELLHUB_BILLING").
35673568
Return("true").
3568-
Twice()
3569+
Once()
35693570
envMock.
3570-
On("Get", "SHELLHUB_ENTERPRISE").
3571-
Return("false").
3571+
On("Get", "SHELLHUB_CLOUD").
3572+
Return("true").
35723573
Once()
35733574
storeMock.
35743575
On("DeviceRemovedGet", ctx, "00000000-0000-0000-0000-000000000000", models.UID("uid")).
@@ -3653,12 +3654,12 @@ func TestUpdateDeviceStatus_cloud_subscription_inactive(t *testing.T) {
36533654
Return(nil, store.ErrNoDocuments).
36543655
Once()
36553656
envMock.
3656-
On("Get", "SHELLHUB_CLOUD").
3657+
On("Get", "SHELLHUB_BILLING").
36573658
Return("true").
3658-
Twice()
3659+
Once()
36593660
envMock.
3660-
On("Get", "SHELLHUB_ENTERPRISE").
3661-
Return("false").
3661+
On("Get", "SHELLHUB_CLOUD").
3662+
Return("true").
36623663
Once()
36633664
storeMock.
36643665
On("DeviceRemovedGet", ctx, "00000000-0000-0000-0000-000000000000", models.UID("uid")).
@@ -3751,12 +3752,12 @@ func TestUpdateDeviceStatus_cloud_subscription_inactive(t *testing.T) {
37513752
Return(nil, store.ErrNoDocuments).
37523753
Once()
37533754
envMock.
3754-
On("Get", "SHELLHUB_CLOUD").
3755+
On("Get", "SHELLHUB_BILLING").
37553756
Return("true").
3756-
Twice()
3757+
Once()
37573758
envMock.
3758-
On("Get", "SHELLHUB_ENTERPRISE").
3759-
Return("false").
3759+
On("Get", "SHELLHUB_CLOUD").
3760+
Return("true").
37603761
Once()
37613762
storeMock.
37623763
On("DeviceRemovedGet", ctx, "00000000-0000-0000-0000-000000000000", models.UID("uid")).
@@ -3827,12 +3828,12 @@ func TestUpdateDeviceStatus_cloud_subscription_inactive(t *testing.T) {
38273828
Return(nil, store.ErrNoDocuments).
38283829
Once()
38293830
envMock.
3830-
On("Get", "SHELLHUB_CLOUD").
3831+
On("Get", "SHELLHUB_BILLING").
38313832
Return("true").
3832-
Twice()
3833+
Once()
38333834
envMock.
3834-
On("Get", "SHELLHUB_ENTERPRISE").
3835-
Return("false").
3835+
On("Get", "SHELLHUB_CLOUD").
3836+
Return("true").
38363837
Once()
38373838
storeMock.
38383839
On("DeviceRemovedGet", ctx, "00000000-0000-0000-0000-000000000000", models.UID("uid")).
@@ -3906,12 +3907,12 @@ func TestUpdateDeviceStatus_cloud_subscription_inactive(t *testing.T) {
39063907
Return(nil, store.ErrNoDocuments).
39073908
Once()
39083909
envMock.
3909-
On("Get", "SHELLHUB_CLOUD").
3910+
On("Get", "SHELLHUB_BILLING").
39103911
Return("true").
3911-
Twice()
3912+
Once()
39123913
envMock.
3913-
On("Get", "SHELLHUB_ENTERPRISE").
3914-
Return("false").
3914+
On("Get", "SHELLHUB_CLOUD").
3915+
Return("true").
39153916
Once()
39163917
storeMock.
39173918
On("DeviceRemovedGet", ctx, "00000000-0000-0000-0000-000000000000", models.UID("uid")).
@@ -3992,12 +3993,12 @@ func TestUpdateDeviceStatus_cloud_subscription_inactive(t *testing.T) {
39923993
Return(nil, store.ErrNoDocuments).
39933994
Once()
39943995
envMock.
3995-
On("Get", "SHELLHUB_CLOUD").
3996+
On("Get", "SHELLHUB_BILLING").
39963997
Return("true").
3997-
Twice()
3998+
Once()
39983999
envMock.
3999-
On("Get", "SHELLHUB_ENTERPRISE").
4000-
Return("false").
4000+
On("Get", "SHELLHUB_CLOUD").
4001+
Return("true").
40014002
Once()
40024003
storeMock.
40034004
On("DeviceRemovedGet", ctx, "00000000-0000-0000-0000-000000000000", models.UID("uid")).
@@ -4082,12 +4083,12 @@ func TestUpdateDeviceStatus_cloud_subscription_inactive(t *testing.T) {
40824083
Return(nil, store.ErrNoDocuments).
40834084
Once()
40844085
envMock.
4085-
On("Get", "SHELLHUB_CLOUD").
4086+
On("Get", "SHELLHUB_BILLING").
40864087
Return("true").
4087-
Twice()
4088+
Once()
40884089
envMock.
4089-
On("Get", "SHELLHUB_ENTERPRISE").
4090-
Return("false").
4090+
On("Get", "SHELLHUB_CLOUD").
4091+
Return("true").
40914092
Once()
40924093
storeMock.
40934094
On("DeviceRemovedGet", ctx, "00000000-0000-0000-0000-000000000000", models.UID("uid")).

0 commit comments

Comments
 (0)