Skip to content

Commit

Permalink
feat: show archived toggles on a project level (#1555)
Browse files Browse the repository at this point in the history
* feat: show archived toggles on a project level

* refactor: split behaviour in 2 separate routes and methods for clarity

* add e2e test
  • Loading branch information
nunogois committed May 4, 2022
1 parent 188352c commit 7e938a2
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 0 deletions.
27 changes: 27 additions & 0 deletions src/lib/routes/admin-api/archive.ts
Expand Up @@ -42,6 +42,20 @@ export default class ArchiveController extends Controller {
],
});

this.route({
method: 'get',
path: '/features/:projectId',
acceptAnyContentType: true,
handler: this.getArchivedFeaturesByProjectId,
middleware: [
openApiService.validPath({
tags: ['admin'],
responses: { 200: featuresResponse },
deprecated: true,
}),
],
});

this.delete('/:featureName', this.deleteFeature, DELETE_FEATURE);
this.post(
'/revive/:featureName',
Expand All @@ -60,6 +74,19 @@ export default class ArchiveController extends Controller {
res.json({ version: 2, features });
}

async getArchivedFeaturesByProjectId(
req: Request<{ projectId: string }, any, any, any>,
res: Response<FeaturesSchema>,
): Promise<void> {
const { projectId } = req.params;
const features =
await this.featureService.getMetadataForAllFeaturesByProjectId(
true,
projectId,
);
res.json({ version: 2, features });
}

async deleteFeature(
req: IAuthRequest<any, { featureName: string }, any, any>,
res: Response,
Expand Down
7 changes: 7 additions & 0 deletions src/lib/services/feature-toggle-service.ts
Expand Up @@ -997,6 +997,13 @@ class FeatureToggleService {
return this.featureToggleStore.getAll({ archived });
}

async getMetadataForAllFeaturesByProjectId(
archived: boolean,
project: string,
): Promise<FeatureToggle[]> {
return this.featureToggleStore.getAll({ archived, project });
}

async getProjectId(name: string): Promise<string> {
return this.featureToggleStore.getProjectId(name);
}
Expand Down
52 changes: 52 additions & 0 deletions src/test/e2e/api/admin/archive.test.ts
Expand Up @@ -68,6 +68,58 @@ test('Should get archived toggles via admin', async () => {
});
});

test('Should get archived toggles via project', async () => {
await db.stores.featureToggleStore.deleteAll();

await db.stores.projectStore.create({
id: 'proj-1',
name: 'proj-1',
description: '',
});
await db.stores.projectStore.create({
id: 'proj-2',
name: 'proj-2',
description: '',
});

await db.stores.featureToggleStore.create('proj-1', {
name: 'feat-proj-1',
archived: true,
});
await db.stores.featureToggleStore.create('proj-2', {
name: 'feat-proj-2',
archived: true,
});
await db.stores.featureToggleStore.create('proj-2', {
name: 'feat-proj-2-2',
archived: true,
});

await app.request
.get('/api/admin/archive/features/proj-1')
.expect(200)
.expect('Content-Type', /json/)
.expect((res) => {
expect(res.body.features).toHaveLength(1);
});

await app.request
.get('/api/admin/archive/features/proj-2')
.expect(200)
.expect('Content-Type', /json/)
.expect((res) => {
expect(res.body.features).toHaveLength(2);
});

await app.request
.get('/api/admin/archive/features')
.expect(200)
.expect('Content-Type', /json/)
.expect((res) => {
expect(res.body.features).toHaveLength(3);
});
});

test('Should be able to revive toggle', async () => {
await app.request.post('/api/admin/projects/default/features').send({
name: 'archived.revival',
Expand Down

8 comments on commit 7e938a2

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coverage report

❌ An unexpected error occurred. For more details, check console

Error: The process '/usr/local/bin/yarn' failed with exit code 1
St.
Category Percentage Covered / Total
🟢 Statements 91.21% 5178/5677
🟡 Branches 79.35% 807/1017
🟢 Functions 86.2% 1218/1413
🟢 Lines 91.13% 5057/5549

Test suite run failed

Failed tests: 1/864. Failed suites: 1/124.
  ● should serve the OpenAPI spec

    expect(received).toMatchSnapshot()

    Snapshot name: `should serve the OpenAPI spec 1`

    - Snapshot  -  0
    + Received  + 30

    @@ -227,10 +227,40 @@
              "tags": Array [
                "admin",
              ],
            },
          },
    +     "/api/admin/archive/features/{projectId}": Object {
    +       "get": Object {
    +         "deprecated": true,
    +         "parameters": Array [
    +           Object {
    +             "in": "path",
    +             "name": "projectId",
    +             "required": true,
    +             "schema": Object {
    +               "type": "string",
    +             },
    +           },
    +         ],
    +         "responses": Object {
    +           "200": Object {
    +             "content": Object {
    +               "application/json": Object {
    +                 "schema": Object {
    +                   "$ref": "#/components/schemas/featuresSchema",
    +                 },
    +               },
    +             },
    +             "description": "featuresResponse",
    +           },
    +         },
    +         "tags": Array [
    +           "admin",
    +         ],
    +       },
    +     },
          "/api/admin/features/": Object {
            "get": Object {
              "deprecated": true,
              "responses": Object {
                "200": Object {

      34 |             // This test will fail whenever there's a change to the API spec.
      35 |             // If the change is intended, update the snapshot with `jest -u`.
    > 36 |             expect(res.body).toMatchSnapshot();
         |                              ^
      37 |         });
      38 | });
      39 |

      at src/test/e2e/api/openapi/openapi.e2e.test.ts:36:30
      at node_modules/supertest/lib/test.js:306:17
      at Test._assertFunction (node_modules/supertest/lib/test.js:285:13)
      at Test.assert (node_modules/supertest/lib/test.js:164:23)
      at Server.localAssert (node_modules/supertest/lib/test.js:120:14)

Report generated by 🧪jest coverage report action from ee15a10

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coverage report

❌ An unexpected error occurred. For more details, check console

Error: The process '/usr/local/bin/yarn' failed with exit code 1
St.
Category Percentage Covered / Total
🟢 Statements 91.21% 5178/5677
🟡 Branches 79.35% 807/1017
🟢 Functions 86.2% 1218/1413
🟢 Lines 91.13% 5057/5549

Test suite run failed

Failed tests: 1/864. Failed suites: 1/124.
  ● should serve the OpenAPI spec

    expect(received).toMatchSnapshot()

    Snapshot name: `should serve the OpenAPI spec 1`

    - Snapshot  -  0
    + Received  + 30

    @@ -227,10 +227,40 @@
              "tags": Array [
                "admin",
              ],
            },
          },
    +     "/api/admin/archive/features/{projectId}": Object {
    +       "get": Object {
    +         "deprecated": true,
    +         "parameters": Array [
    +           Object {
    +             "in": "path",
    +             "name": "projectId",
    +             "required": true,
    +             "schema": Object {
    +               "type": "string",
    +             },
    +           },
    +         ],
    +         "responses": Object {
    +           "200": Object {
    +             "content": Object {
    +               "application/json": Object {
    +                 "schema": Object {
    +                   "$ref": "#/components/schemas/featuresSchema",
    +                 },
    +               },
    +             },
    +             "description": "featuresResponse",
    +           },
    +         },
    +         "tags": Array [
    +           "admin",
    +         ],
    +       },
    +     },
          "/api/admin/features/": Object {
            "get": Object {
              "deprecated": true,
              "responses": Object {
                "200": Object {

      34 |             // This test will fail whenever there's a change to the API spec.
      35 |             // If the change is intended, update the snapshot with `jest -u`.
    > 36 |             expect(res.body).toMatchSnapshot();
         |                              ^
      37 |         });
      38 | });
      39 |

      at src/test/e2e/api/openapi/openapi.e2e.test.ts:36:30
      at node_modules/supertest/lib/test.js:306:17
      at Test._assertFunction (node_modules/supertest/lib/test.js:285:13)
      at Test.assert (node_modules/supertest/lib/test.js:164:23)
      at Server.localAssert (node_modules/supertest/lib/test.js:120:14)

Report generated by 🧪jest coverage report action from ee15a10

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coverage report

❌ An unexpected error occurred. For more details, check console

Error: The process '/usr/local/bin/yarn' failed with exit code 1
St.
Category Percentage Covered / Total
🟢 Statements 91.21% 5178/5677
🟡 Branches 79.35% 807/1017
🟢 Functions 86.2% 1218/1413
🟢 Lines 91.13% 5057/5549

Test suite run failed

Failed tests: 1/864. Failed suites: 1/124.
  ● should serve the OpenAPI spec

    expect(received).toMatchSnapshot()

    Snapshot name: `should serve the OpenAPI spec 1`

    - Snapshot  -  0
    + Received  + 30

    @@ -227,10 +227,40 @@
              "tags": Array [
                "admin",
              ],
            },
          },
    +     "/api/admin/archive/features/{projectId}": Object {
    +       "get": Object {
    +         "deprecated": true,
    +         "parameters": Array [
    +           Object {
    +             "in": "path",
    +             "name": "projectId",
    +             "required": true,
    +             "schema": Object {
    +               "type": "string",
    +             },
    +           },
    +         ],
    +         "responses": Object {
    +           "200": Object {
    +             "content": Object {
    +               "application/json": Object {
    +                 "schema": Object {
    +                   "$ref": "#/components/schemas/featuresSchema",
    +                 },
    +               },
    +             },
    +             "description": "featuresResponse",
    +           },
    +         },
    +         "tags": Array [
    +           "admin",
    +         ],
    +       },
    +     },
          "/api/admin/features/": Object {
            "get": Object {
              "deprecated": true,
              "responses": Object {
                "200": Object {

      34 |             // This test will fail whenever there's a change to the API spec.
      35 |             // If the change is intended, update the snapshot with `jest -u`.
    > 36 |             expect(res.body).toMatchSnapshot();
         |                              ^
      37 |         });
      38 | });
      39 |

      at src/test/e2e/api/openapi/openapi.e2e.test.ts:36:30
      at node_modules/supertest/lib/test.js:306:17
      at Test._assertFunction (node_modules/supertest/lib/test.js:285:13)
      at Test.assert (node_modules/supertest/lib/test.js:164:23)
      at Server.localAssert (node_modules/supertest/lib/test.js:120:14)

Report generated by 🧪jest coverage report action from 9972bc3

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coverage report

❌ An unexpected error occurred. For more details, check console

Error: The process '/usr/local/bin/yarn' failed with exit code 1
St.
Category Percentage Covered / Total
🟢 Statements 91.21% 5178/5677
🟡 Branches 79.35% 807/1017
🟢 Functions 86.2% 1218/1413
🟢 Lines 91.13% 5057/5549

Test suite run failed

Failed tests: 1/864. Failed suites: 1/124.
  ● should serve the OpenAPI spec

    expect(received).toMatchSnapshot()

    Snapshot name: `should serve the OpenAPI spec 1`

    - Snapshot  -  0
    + Received  + 30

    @@ -227,10 +227,40 @@
              "tags": Array [
                "admin",
              ],
            },
          },
    +     "/api/admin/archive/features/{projectId}": Object {
    +       "get": Object {
    +         "deprecated": true,
    +         "parameters": Array [
    +           Object {
    +             "in": "path",
    +             "name": "projectId",
    +             "required": true,
    +             "schema": Object {
    +               "type": "string",
    +             },
    +           },
    +         ],
    +         "responses": Object {
    +           "200": Object {
    +             "content": Object {
    +               "application/json": Object {
    +                 "schema": Object {
    +                   "$ref": "#/components/schemas/featuresSchema",
    +                 },
    +               },
    +             },
    +             "description": "featuresResponse",
    +           },
    +         },
    +         "tags": Array [
    +           "admin",
    +         ],
    +       },
    +     },
          "/api/admin/features/": Object {
            "get": Object {
              "deprecated": true,
              "responses": Object {
                "200": Object {

      34 |             // This test will fail whenever there's a change to the API spec.
      35 |             // If the change is intended, update the snapshot with `jest -u`.
    > 36 |             expect(res.body).toMatchSnapshot();
         |                              ^
      37 |         });
      38 | });
      39 |

      at src/test/e2e/api/openapi/openapi.e2e.test.ts:36:30
      at node_modules/supertest/lib/test.js:306:17
      at Test._assertFunction (node_modules/supertest/lib/test.js:285:13)
      at Test.assert (node_modules/supertest/lib/test.js:164:23)
      at Server.localAssert (node_modules/supertest/lib/test.js:120:14)

Report generated by 🧪jest coverage report action from 8e4fb95

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coverage report

❌ An unexpected error occurred. For more details, check console

Error: The process '/usr/local/bin/yarn' failed with exit code 1
St.
Category Percentage Covered / Total
🟢 Statements 91.21% 5178/5677
🟡 Branches 79.35% 807/1017
🟢 Functions 86.2% 1218/1413
🟢 Lines 91.13% 5057/5549

Test suite run failed

Failed tests: 1/864. Failed suites: 1/124.
  ● should serve the OpenAPI spec

    expect(received).toMatchSnapshot()

    Snapshot name: `should serve the OpenAPI spec 1`

    - Snapshot  -  0
    + Received  + 30

    @@ -227,10 +227,40 @@
              "tags": Array [
                "admin",
              ],
            },
          },
    +     "/api/admin/archive/features/{projectId}": Object {
    +       "get": Object {
    +         "deprecated": true,
    +         "parameters": Array [
    +           Object {
    +             "in": "path",
    +             "name": "projectId",
    +             "required": true,
    +             "schema": Object {
    +               "type": "string",
    +             },
    +           },
    +         ],
    +         "responses": Object {
    +           "200": Object {
    +             "content": Object {
    +               "application/json": Object {
    +                 "schema": Object {
    +                   "$ref": "#/components/schemas/featuresSchema",
    +                 },
    +               },
    +             },
    +             "description": "featuresResponse",
    +           },
    +         },
    +         "tags": Array [
    +           "admin",
    +         ],
    +       },
    +     },
          "/api/admin/features/": Object {
            "get": Object {
              "deprecated": true,
              "responses": Object {
                "200": Object {

      34 |             // This test will fail whenever there's a change to the API spec.
      35 |             // If the change is intended, update the snapshot with `jest -u`.
    > 36 |             expect(res.body).toMatchSnapshot();
         |                              ^
      37 |         });
      38 | });
      39 |

      at src/test/e2e/api/openapi/openapi.e2e.test.ts:36:30
      at node_modules/supertest/lib/test.js:306:17
      at Test._assertFunction (node_modules/supertest/lib/test.js:285:13)
      at Test.assert (node_modules/supertest/lib/test.js:164:23)
      at Server.localAssert (node_modules/supertest/lib/test.js:120:14)

Report generated by 🧪jest coverage report action from d365191

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coverage report

❌ An unexpected error occurred. For more details, check console

Error: The process '/usr/local/bin/yarn' failed with exit code 1
St.
Category Percentage Covered / Total
🟢 Statements 91.21% 5178/5677
🟡 Branches 79.35% 807/1017
🟢 Functions 86.2% 1218/1413
🟢 Lines 91.13% 5057/5549

Test suite run failed

Failed tests: 1/864. Failed suites: 1/124.
  ● should serve the OpenAPI spec

    expect(received).toMatchSnapshot()

    Snapshot name: `should serve the OpenAPI spec 1`

    - Snapshot  -  0
    + Received  + 30

    @@ -227,10 +227,40 @@
              "tags": Array [
                "admin",
              ],
            },
          },
    +     "/api/admin/archive/features/{projectId}": Object {
    +       "get": Object {
    +         "deprecated": true,
    +         "parameters": Array [
    +           Object {
    +             "in": "path",
    +             "name": "projectId",
    +             "required": true,
    +             "schema": Object {
    +               "type": "string",
    +             },
    +           },
    +         ],
    +         "responses": Object {
    +           "200": Object {
    +             "content": Object {
    +               "application/json": Object {
    +                 "schema": Object {
    +                   "$ref": "#/components/schemas/featuresSchema",
    +                 },
    +               },
    +             },
    +             "description": "featuresResponse",
    +           },
    +         },
    +         "tags": Array [
    +           "admin",
    +         ],
    +       },
    +     },
          "/api/admin/features/": Object {
            "get": Object {
              "deprecated": true,
              "responses": Object {
                "200": Object {

      34 |             // This test will fail whenever there's a change to the API spec.
      35 |             // If the change is intended, update the snapshot with `jest -u`.
    > 36 |             expect(res.body).toMatchSnapshot();
         |                              ^
      37 |         });
      38 | });
      39 |

      at src/test/e2e/api/openapi/openapi.e2e.test.ts:36:30
      at node_modules/supertest/lib/test.js:306:17
      at Test._assertFunction (node_modules/supertest/lib/test.js:285:13)
      at Test.assert (node_modules/supertest/lib/test.js:164:23)
      at Server.localAssert (node_modules/supertest/lib/test.js:120:14)

Report generated by 🧪jest coverage report action from 03d12f4

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coverage report

❌ An unexpected error occurred. For more details, check console

Error: The process '/usr/local/bin/yarn' failed with exit code 1
St.
Category Percentage Covered / Total
🟢 Statements 91.21% 5178/5677
🟡 Branches 79.35% 807/1017
🟢 Functions 86.2% 1218/1413
🟢 Lines 91.13% 5057/5549

Test suite run failed

Failed tests: 1/864. Failed suites: 1/124.
  ● should serve the OpenAPI spec

    expect(received).toMatchSnapshot()

    Snapshot name: `should serve the OpenAPI spec 1`

    - Snapshot  -  0
    + Received  + 30

    @@ -227,10 +227,40 @@
              "tags": Array [
                "admin",
              ],
            },
          },
    +     "/api/admin/archive/features/{projectId}": Object {
    +       "get": Object {
    +         "deprecated": true,
    +         "parameters": Array [
    +           Object {
    +             "in": "path",
    +             "name": "projectId",
    +             "required": true,
    +             "schema": Object {
    +               "type": "string",
    +             },
    +           },
    +         ],
    +         "responses": Object {
    +           "200": Object {
    +             "content": Object {
    +               "application/json": Object {
    +                 "schema": Object {
    +                   "$ref": "#/components/schemas/featuresSchema",
    +                 },
    +               },
    +             },
    +             "description": "featuresResponse",
    +           },
    +         },
    +         "tags": Array [
    +           "admin",
    +         ],
    +       },
    +     },
          "/api/admin/features/": Object {
            "get": Object {
              "deprecated": true,
              "responses": Object {
                "200": Object {

      34 |             // This test will fail whenever there's a change to the API spec.
      35 |             // If the change is intended, update the snapshot with `jest -u`.
    > 36 |             expect(res.body).toMatchSnapshot();
         |                              ^
      37 |         });
      38 | });
      39 |

      at src/test/e2e/api/openapi/openapi.e2e.test.ts:36:30
      at node_modules/supertest/lib/test.js:306:17
      at Test._assertFunction (node_modules/supertest/lib/test.js:285:13)
      at Test.assert (node_modules/supertest/lib/test.js:164:23)
      at Server.localAssert (node_modules/supertest/lib/test.js:120:14)

Report generated by 🧪jest coverage report action from dbe19d0

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coverage report

❌ An unexpected error occurred. For more details, check console

Error: The process '/usr/local/bin/yarn' failed with exit code 1
St.
Category Percentage Covered / Total
🟢 Statements 91.21% 5178/5677
🟡 Branches 79.35% 807/1017
🟢 Functions 86.2% 1218/1413
🟢 Lines 91.13% 5057/5549

Test suite run failed

Failed tests: 1/864. Failed suites: 1/124.
  ● should serve the OpenAPI spec

    expect(received).toMatchSnapshot()

    Snapshot name: `should serve the OpenAPI spec 1`

    - Snapshot  -  0
    + Received  + 30

    @@ -227,10 +227,40 @@
              "tags": Array [
                "admin",
              ],
            },
          },
    +     "/api/admin/archive/features/{projectId}": Object {
    +       "get": Object {
    +         "deprecated": true,
    +         "parameters": Array [
    +           Object {
    +             "in": "path",
    +             "name": "projectId",
    +             "required": true,
    +             "schema": Object {
    +               "type": "string",
    +             },
    +           },
    +         ],
    +         "responses": Object {
    +           "200": Object {
    +             "content": Object {
    +               "application/json": Object {
    +                 "schema": Object {
    +                   "$ref": "#/components/schemas/featuresSchema",
    +                 },
    +               },
    +             },
    +             "description": "featuresResponse",
    +           },
    +         },
    +         "tags": Array [
    +           "admin",
    +         ],
    +       },
    +     },
          "/api/admin/features/": Object {
            "get": Object {
              "deprecated": true,
              "responses": Object {
                "200": Object {

      34 |             // This test will fail whenever there's a change to the API spec.
      35 |             // If the change is intended, update the snapshot with `jest -u`.
    > 36 |             expect(res.body).toMatchSnapshot();
         |                              ^
      37 |         });
      38 | });
      39 |

      at src/test/e2e/api/openapi/openapi.e2e.test.ts:36:30
      at node_modules/supertest/lib/test.js:306:17
      at Test._assertFunction (node_modules/supertest/lib/test.js:285:13)
      at Test.assert (node_modules/supertest/lib/test.js:164:23)
      at Server.localAssert (node_modules/supertest/lib/test.js:120:14)

Report generated by 🧪jest coverage report action from 9972bc3

Please sign in to comment.