From bc3744d56566b6a173f5473344557f0ad7f72e0b Mon Sep 17 00:00:00 2001 From: Fredrik Strand Oseberg Date: Fri, 2 Dec 2022 13:10:39 +0100 Subject: [PATCH] fix: remove stray only (#2589) This removes stray onlys in our tests and adds a linter rule that will error if only is present. Also updates the test result of one of our tests as a result of [this pull request](https://github.com/Unleash/unleash/pull/2344) --- .eslintrc | 3 ++- package.json | 1 + src/lib/services/feature-toggle-service.ts | 1 + src/test/e2e/api/admin/project/features.e2e.test.ts | 6 +++--- src/test/e2e/api/proxy/proxy.e2e.test.ts | 2 +- yarn.lock | 5 +++++ 6 files changed, 13 insertions(+), 5 deletions(-) diff --git a/.eslintrc b/.eslintrc index 8988e889d5..c97cca85d3 100644 --- a/.eslintrc +++ b/.eslintrc @@ -9,7 +9,7 @@ "ecmaVersion": 2019, "project": "./tsconfig.json" }, - "plugins": ["@typescript-eslint", "prettier", "import"], + "plugins": ["@typescript-eslint", "prettier", "import", "no-only-tests"], "root": true, "rules": { "@typescript-eslint/no-var-requires": 0, @@ -26,6 +26,7 @@ "no-param-reassign": "error", "no-return-await": "error", "max-nested-callbacks": "off", + "no-only-tests/no-only-tests": "error", "new-cap": [ "error", { diff --git a/package.json b/package.json index 95ff7845be..3ac1fb2c69 100644 --- a/package.json +++ b/package.json @@ -170,6 +170,7 @@ "eslint-config-airbnb-typescript": "17.0.0", "eslint-config-prettier": "8.5.0", "eslint-plugin-import": "2.26.0", + "eslint-plugin-no-only-tests": "^3.1.0", "eslint-plugin-prettier": "4.2.1", "faker": "5.5.3", "fast-check": "3.3.0", diff --git a/src/lib/services/feature-toggle-service.ts b/src/lib/services/feature-toggle-service.ts index 9ce07b8589..a272142e73 100644 --- a/src/lib/services/feature-toggle-service.ts +++ b/src/lib/services/feature-toggle-service.ts @@ -167,6 +167,7 @@ class FeatureToggleService { projectId, }: IFeatureContext): Promise { const id = await this.featureToggleStore.getProjectId(featureName); + if (id !== projectId) { throw new InvalidOperationError( `The operation could not be completed. The feature exists, but the provided project id ("${projectId}") does not match the project that the feature belongs to ("${id}"). Try using "${id}" in the request URL instead of "${projectId}".`, diff --git a/src/test/e2e/api/admin/project/features.e2e.test.ts b/src/test/e2e/api/admin/project/features.e2e.test.ts index a5040c9bf0..15c352fbec 100644 --- a/src/test/e2e/api/admin/project/features.e2e.test.ts +++ b/src/test/e2e/api/admin/project/features.e2e.test.ts @@ -515,7 +515,7 @@ test('Trying to toggle environment that does not exist yields 404', async () => test('Getting feature that does not exist should yield 404', async () => { await app.request .get('/api/admin/projects/default/features/non.existing.feature') - .expect(404); + .expect(403); }); describe('Interacting with features using project IDs that belong to other projects', () => { @@ -2630,7 +2630,7 @@ test('should return strategies in correct order when new strategies are added', expect(strategiesReOrdered[3].id).toBe(strategyThree.id); }); -test.only('should create a strategy with segments', async () => { +test('should create a strategy with segments', async () => { const feature = { name: uuidv4(), impressionData: false }; await createFeatureToggle(feature.name); const segment = await createSegment('segmentOne'); @@ -2678,7 +2678,7 @@ test.only('should create a strategy with segments', async () => { }); }); -test.only('should add multiple segments to a strategy', async () => { +test('should add multiple segments to a strategy', async () => { const feature = { name: uuidv4(), impressionData: false }; await createFeatureToggle(feature.name); const segment = await createSegment('seg1'); diff --git a/src/test/e2e/api/proxy/proxy.e2e.test.ts b/src/test/e2e/api/proxy/proxy.e2e.test.ts index 0ad7c65a40..16d5521fe3 100644 --- a/src/test/e2e/api/proxy/proxy.e2e.test.ts +++ b/src/test/e2e/api/proxy/proxy.e2e.test.ts @@ -982,7 +982,7 @@ test('should return all features when specified', async () => { }); }); -test.only('should return maxAge header on options call', async () => { +test('should return maxAge header on options call', async () => { await app.request .options('/api/frontend') .set('Origin', 'https://example.com') diff --git a/yarn.lock b/yarn.lock index 68d28b2a4d..35d9feb75b 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3185,6 +3185,11 @@ eslint-plugin-import@2.26.0: resolve "^1.22.0" tsconfig-paths "^3.14.1" +eslint-plugin-no-only-tests@^3.1.0: + version "3.1.0" + resolved "https://registry.yarnpkg.com/eslint-plugin-no-only-tests/-/eslint-plugin-no-only-tests-3.1.0.tgz#f38e4935c6c6c4842bf158b64aaa20c366fe171b" + integrity sha512-Lf4YW/bL6Un1R6A76pRZyE1dl1vr31G/ev8UzIc/geCgFWyrKil8hVjYqWVKGB/UIGmb6Slzs9T0wNezdSVegw== + eslint-plugin-prettier@4.2.1: version "4.2.1" resolved "https://registry.yarnpkg.com/eslint-plugin-prettier/-/eslint-plugin-prettier-4.2.1.tgz#651cbb88b1dab98bfd42f017a12fa6b2d993f94b"