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
18 changes: 17 additions & 1 deletion api/e2etests/e2e_seed_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,12 @@
from environments.identities.models import Identity
from environments.models import Environment
from environments.permissions.models import UserEnvironmentPermission
from organisations.models import Organisation, OrganisationRole, Subscription
from organisations.models import (
Organisation,
OrganisationRole,
OrganisationSubscriptionInformationCache,
Subscription,
)
from organisations.permissions.models import UserOrganisationPermission
from organisations.permissions.permissions import (
CREATE_PROJECT,
Expand Down Expand Up @@ -143,6 +148,17 @@ def seed_data() -> None:
Subscription.objects.filter(organisation__in=org_admin.organisations.all()).update(
max_seats=8, plan=ENTERPRISE, subscription_id="test_subscription_id"
)
# On SaaS, plan limits such as audit log visibility come from the
# subscription information cache, which starts with free plan limits.
for subscription_cache in OrganisationSubscriptionInformationCache.objects.filter(
organisation__in=org_admin.organisations.all()
).select_related("organisation__subscription"):
subscription = subscription_cache.organisation.subscription
subscription_cache.upgrade_to_enterprise(
seats=subscription.max_seats,
api_calls=subscription.max_api_calls,
)
subscription_cache.save()

# Create projects and environments
projects = []
Expand Down
Empty file.
31 changes: 31 additions & 0 deletions api/tests/unit/e2etests/test_unit_e2etests_seed_data.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import pytest
from django.conf import settings

from e2etests.e2e_seed_data import seed_data
from organisations.models import OrganisationSubscriptionInformationCache
from users.models import FFAdminUser


@pytest.mark.saas_mode
@pytest.mark.django_db
def test_seed_data__saas__lifts_e2e_organisation_plan_limits() -> None:
# Given / When
seed_data()

# Then
e2e_user = FFAdminUser.objects.get(email=settings.E2E_USER)
organisation = e2e_user.organisations.get()
subscription_cache = organisation.subscription_information_cache
assert subscription_cache.allowed_seats == 8
assert subscription_cache.allowed_projects is None
assert subscription_cache.audit_log_visibility_days is None
assert subscription_cache.feature_history_visibility_days is None


@pytest.mark.django_db
def test_seed_data__self_hosted__creates_no_subscription_information_cache() -> None:
# Given / When
seed_data()

# Then
assert not OrganisationSubscriptionInformationCache.objects.exists()
Comment thread
khvn26 marked this conversation as resolved.
Resolved
8 changes: 8 additions & 0 deletions frontend/e2e/helpers/utils.playwright.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,11 @@ export const getFlagsmith = async function (): Promise<IFlagsmith> {
await initProm;
return flagsmith as IFlagsmith;
};

// Whether the API under test is a SaaS deployment, per its `/version/` endpoint.
export const isSaas = async function (): Promise<boolean> {
const api = process.env.FLAGSMITH_API_URL || Project.api;
const res = await fetch(`${api.replace(/api\/v1\/$/, '')}version/`);
Comment thread
khvn26 marked this conversation as resolved.
Resolved
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
const version = (await res.json()) as { is_saas?: boolean };
Comment thread
khvn26 marked this conversation as resolved.
Resolved
return !!version.is_saas;
};
6 changes: 5 additions & 1 deletion frontend/e2e/tests/segment-test.pw.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { test, expect } from '../test-setup';
import { byId, log, createHelpers, visualSnapshot, getFlagsmith } from '../helpers';
import { byId, log, createHelpers, visualSnapshot, getFlagsmith, isSaas } from '../helpers';
import { E2E_USER, PASSWORD, E2E_TEST_IDENTITY, E2E_SEGMENT_PROJECT_1, E2E_SEGMENT_PROJECT_2, E2E_SEGMENT_PROJECT_3 } from '../config'

const REMOTE_CONFIG_FEATURE = 'remote_config'
Expand Down Expand Up @@ -477,6 +477,10 @@ test('Segment test 4 - Create ANY rule type segment and verify match changes whe
})

test('Segment test 5 - Audit log shows segment rule changes @enterprise', async ({ page }) => {
test.skip(
await isSaas(),
'The E2E organisation has no audit log visibility on SaaS until the seeded subscription is deployed',
Comment thread
khvn26 marked this conversation as resolved.
Resolved
)
const {
click,
createSegment,
Expand Down
Loading