Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import { beforeEach, describe, expect, it, vi } from 'vitest'
import { ref } from 'vue'

const mockIsCloud = vi.hoisted(() => ({ value: true }))
vi.mock('@/platform/distribution/types', () => ({
get isCloud() {
return mockIsCloud.value
}
}))

const mockFlags = vi.hoisted(() => ({ freeTierJobAllowanceEnabled: true }))
vi.mock('@/composables/useFeatureFlags', () => ({
useFeatureFlags: () => ({ flags: mockFlags })
}))

vi.mock('@/composables/node/usePriceBadge', () => ({
useCreditsBadgesInGraph: () => ref([])
}))

const mockRemoteConfig = vi.hoisted(() => ({
value: { free_tier_balance: { allowance: 5, remaining: 5 } }
}))
vi.mock('@/platform/remoteConfig/remoteConfig', () => ({
get remoteConfig() {
return ref(mockRemoteConfig.value)
}
}))

async function loadQuota() {
vi.resetModules()
const { useFreeTierQuota } = await import('./useFreeTierQuota')
return useFreeTierQuota()
}

describe('useFreeTierQuota', () => {
beforeEach(() => {
mockIsCloud.value = true
mockFlags.freeTierJobAllowanceEnabled = true
mockRemoteConfig.value = {
free_tier_balance: { allowance: 5, remaining: 5 }
}
})

it('enables the quota on Cloud when the flag and an allowance are present', async () => {
const quota = await loadQuota()

expect(quota.quotaEnabled.value).toBe(true)
expect(quota.freeTierExecutionPermitted.value).toBe(true)
})
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved

it('keeps the quota disabled off Cloud even when the flag and an allowance are present', async () => {
mockIsCloud.value = false

const quota = await loadQuota()

expect(quota.quotaEnabled.value).toBe(false)
expect(quota.freeTierExecutionPermitted.value).toBe(false)
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { computed, ref, watch } from 'vue'

import { useCreditsBadgesInGraph } from '@/composables/node/usePriceBadge'
import { useFeatureFlags } from '@/composables/useFeatureFlags'
import { isCloud } from '@/platform/distribution/types'
import { remoteConfig } from '@/platform/remoteConfig/remoteConfig'

export const useFreeTierQuota = createSharedComposable(function () {
Expand All @@ -23,7 +24,7 @@ export const useFreeTierQuota = createSharedComposable(function () {
)

const quotaEnabled = computed(
() => flags.freeTierJobAllowanceEnabled && maxAvailable.value > 0
() => isCloud && flags.freeTierJobAllowanceEnabled && maxAvailable.value > 0
)
const hasInvalidNodes = computed(() => creditsBadges.value.length > 0)
const freeTierExecutionPermitted = computed(
Expand Down
Loading