github.com/turbot/steampipe@v1.7.0-rc.0.0.20240517123944-7cef272d4458/ui/dashboard/src/utils/schema.test.ts (about)

     1  import {
     2    DashboardActions,
     3    DashboardExecutionEventWithSchema,
     4    DashboardSnapshot,
     5  } from "../types";
     6  import {
     7    EXECUTION_COMPLETE_SCHEMA_VERSION_LATEST,
     8    EXECUTION_SCHEMA_VERSION_20220614,
     9    EXECUTION_SCHEMA_VERSION_20220929,
    10    EXECUTION_SCHEMA_VERSION_20221222,
    11  } from "../constants/versions";
    12  import {
    13    ExecutionCompleteSchemaMigrator,
    14    ExecutionStartedSchemaMigrator,
    15    SnapshotDataToExecutionCompleteSchemaMigrator,
    16  } from "./schema";
    17  
    18  describe("schema", () => {
    19    describe("execution_started schema migrations", () => {
    20      test("Schema 20220614 to 20221222", () => {
    21        const inputEvent: DashboardExecutionEventWithSchema = {
    22          action: "execution_started",
    23          schema_version: EXECUTION_SCHEMA_VERSION_20220614,
    24          execution_id: "0x140029247e0",
    25          layout: {
    26            name: "aws_insights.dashboard.aws_iam_user_dashboard",
    27            panel_type: "dashboard",
    28            children: [
    29              {
    30                name: "aws_insights.container.dashboard_aws_iam_user_dashboard_anonymous_container_0",
    31                panel_type: "container",
    32              },
    33            ],
    34          },
    35          panels: {
    36            "aws_insights.dashboard.aws_iam_user_dashboard": {
    37              name: "aws_insights.dashboard.aws_iam_user_dashboard",
    38              // @ts-ignore
    39              status: "ready",
    40            },
    41            "aws_insights.container.dashboard_aws_iam_user_dashboard_anonymous_container_0":
    42              {
    43                name: "aws_insights.container.dashboard_aws_iam_user_dashboard_anonymous_container_0",
    44                // @ts-ignore
    45                status: "ready",
    46              },
    47          },
    48          inputs: {
    49            "input.foo": "bar",
    50          },
    51          variables: {
    52            foo: "bar",
    53          },
    54        };
    55  
    56        const eventMigrator = new ExecutionStartedSchemaMigrator();
    57        const migratedEvent = eventMigrator.toLatest(inputEvent);
    58  
    59        const expectedPanels = {
    60          "aws_insights.dashboard.aws_iam_user_dashboard": {
    61            name: "aws_insights.dashboard.aws_iam_user_dashboard",
    62            status: "running",
    63          },
    64          "aws_insights.container.dashboard_aws_iam_user_dashboard_anonymous_container_0":
    65            {
    66              name: "aws_insights.container.dashboard_aws_iam_user_dashboard_anonymous_container_0",
    67              status: "running",
    68            },
    69        };
    70  
    71        const expectedEvent = {
    72          action: inputEvent.action,
    73          schema_version: EXECUTION_COMPLETE_SCHEMA_VERSION_LATEST,
    74          execution_id: inputEvent.execution_id,
    75          layout: inputEvent.layout,
    76          panels: expectedPanels,
    77          inputs: inputEvent.inputs,
    78          variables: inputEvent.variables,
    79        };
    80  
    81        expect(migratedEvent).toEqual(expect.objectContaining(expectedEvent));
    82      });
    83  
    84      test("Unsupported schema", () => {
    85        const inputEvent: DashboardExecutionEventWithSchema = {
    86          // @ts-ignore
    87          schema_version: "20221010",
    88        };
    89  
    90        const eventMigrator = new ExecutionCompleteSchemaMigrator();
    91  
    92        expect(() => eventMigrator.toLatest(inputEvent)).toThrow(
    93          `Unsupported dashboard event schema ${inputEvent.schema_version}`
    94        );
    95      });
    96    });
    97  
    98    describe("execution_complete schema migrations", () => {
    99      test("Schema 20220614 to 20221222", () => {
   100        const inputEvent: DashboardExecutionEventWithSchema = {
   101          action: "execution_complete",
   102          schema_version: EXECUTION_SCHEMA_VERSION_20220614,
   103          execution_id: "0x140029247e0",
   104          dashboard_node: {
   105            name: "aws_insights.dashboard.aws_iam_user_dashboard",
   106          },
   107          layout: {
   108            name: "aws_insights.dashboard.aws_iam_user_dashboard",
   109            panel_type: "dashboard",
   110            children: [
   111              {
   112                name: "aws_insights.container.dashboard_aws_iam_user_dashboard_anonymous_container_0",
   113                panel_type: "container",
   114              },
   115            ],
   116          },
   117          panels: {
   118            "aws_insights.dashboard.aws_iam_user_dashboard": {
   119              name: "aws_insights.dashboard.aws_iam_user_dashboard",
   120              // @ts-ignore
   121              status: "ready",
   122            },
   123            "aws_insights.container.dashboard_aws_iam_user_dashboard_anonymous_container_0":
   124              {
   125                name: "aws_insights.container.dashboard_aws_iam_user_dashboard_anonymous_container_0",
   126                // @ts-ignore
   127                status: "ready",
   128              },
   129          },
   130          inputs: {
   131            "input.foo": "bar",
   132          },
   133          variables: {
   134            foo: "bar",
   135          },
   136          search_path: ["some_schema"],
   137          start_time: "2022-10-27T14:43:57.79514+01:00",
   138          end_time: "2022-10-27T14:43:58.045925+01:00",
   139        };
   140  
   141        const eventMigrator = new ExecutionCompleteSchemaMigrator();
   142        const migratedEvent = eventMigrator.toLatest(inputEvent);
   143  
   144        const expectedPanels = {
   145          "aws_insights.dashboard.aws_iam_user_dashboard": {
   146            name: "aws_insights.dashboard.aws_iam_user_dashboard",
   147            status: "running",
   148          },
   149          "aws_insights.container.dashboard_aws_iam_user_dashboard_anonymous_container_0":
   150            {
   151              name: "aws_insights.container.dashboard_aws_iam_user_dashboard_anonymous_container_0",
   152              status: "running",
   153            },
   154        };
   155  
   156        const expectedEvent = {
   157          action: inputEvent.action,
   158          schema_version: EXECUTION_COMPLETE_SCHEMA_VERSION_LATEST,
   159          execution_id: inputEvent.execution_id,
   160          snapshot: {
   161            schema_version: EXECUTION_COMPLETE_SCHEMA_VERSION_LATEST,
   162            layout: inputEvent.layout,
   163            panels: expectedPanels,
   164            inputs: inputEvent.inputs,
   165            variables: inputEvent.variables,
   166            search_path: inputEvent.search_path,
   167            end_time: inputEvent.end_time,
   168            start_time: inputEvent.start_time,
   169          },
   170        };
   171  
   172        expect(migratedEvent).toEqual(expectedEvent);
   173      });
   174  
   175      test("Schema 20220929 to 20221222", () => {
   176        const inputEvent: DashboardExecutionEventWithSchema = {
   177          action: "execution_complete",
   178          schema_version: EXECUTION_SCHEMA_VERSION_20220929,
   179          execution_id: "0x140029247e0",
   180          snapshot: {
   181            schema_version: EXECUTION_SCHEMA_VERSION_20220929,
   182            layout: {
   183              name: "aws_insights.dashboard.aws_iam_user_dashboard",
   184              panel_type: "dashboard",
   185              children: [
   186                {
   187                  name: "aws_insights.container.dashboard_aws_iam_user_dashboard_anonymous_container_0",
   188                  panel_type: "container",
   189                },
   190              ],
   191            },
   192            panels: {
   193              "aws_insights.dashboard.aws_iam_user_dashboard": {
   194                name: "aws_insights.dashboard.aws_iam_user_dashboard",
   195                // @ts-ignore
   196                status: "ready",
   197              },
   198              "aws_insights.container.dashboard_aws_iam_user_dashboard_anonymous_container_0":
   199                {
   200                  name: "aws_insights.container.dashboard_aws_iam_user_dashboard_anonymous_container_0",
   201                  // @ts-ignore
   202                  status: "ready",
   203                },
   204            },
   205            inputs: {
   206              "input.foo": "bar",
   207            },
   208            variables: {
   209              foo: "bar",
   210            },
   211            search_path: ["some_schema"],
   212            start_time: "2022-10-27T14:43:57.79514+01:00",
   213            end_time: "2022-10-27T14:43:58.045925+01:00",
   214          },
   215        };
   216  
   217        const eventMigrator = new ExecutionCompleteSchemaMigrator();
   218        const migratedEvent = eventMigrator.toLatest(inputEvent);
   219  
   220        const expectedPanels = {
   221          "aws_insights.dashboard.aws_iam_user_dashboard": {
   222            name: "aws_insights.dashboard.aws_iam_user_dashboard",
   223            status: "running",
   224          },
   225          "aws_insights.container.dashboard_aws_iam_user_dashboard_anonymous_container_0":
   226            {
   227              name: "aws_insights.container.dashboard_aws_iam_user_dashboard_anonymous_container_0",
   228              status: "running",
   229            },
   230        };
   231  
   232        const expectedEvent = {
   233          action: inputEvent.action,
   234          schema_version: EXECUTION_COMPLETE_SCHEMA_VERSION_LATEST,
   235          execution_id: inputEvent.execution_id,
   236          snapshot: {
   237            schema_version: EXECUTION_COMPLETE_SCHEMA_VERSION_LATEST,
   238            layout: inputEvent.snapshot.layout,
   239            panels: expectedPanels,
   240            inputs: inputEvent.snapshot.inputs,
   241            variables: inputEvent.snapshot.variables,
   242            search_path: inputEvent.snapshot.search_path,
   243            start_time: inputEvent.snapshot.start_time,
   244            end_time: inputEvent.snapshot.end_time,
   245          },
   246        };
   247  
   248        expect(migratedEvent).toEqual(expectedEvent);
   249      });
   250  
   251      test("Schema 20221222 to 20221222", () => {
   252        const inputEvent: DashboardExecutionEventWithSchema = {
   253          action: "execution_complete",
   254          schema_version: EXECUTION_SCHEMA_VERSION_20221222,
   255          execution_id: "0x140029247e0",
   256          snapshot: {
   257            schema_version: EXECUTION_SCHEMA_VERSION_20221222,
   258            layout: {
   259              name: "aws_insights.dashboard.aws_iam_user_dashboard",
   260              panel_type: "dashboard",
   261              children: [
   262                {
   263                  name: "aws_insights.container.dashboard_aws_iam_user_dashboard_anonymous_container_0",
   264                  panel_type: "container",
   265                },
   266              ],
   267            },
   268            panels: {
   269              "aws_insights.dashboard.aws_iam_user_dashboard": {
   270                name: "aws_insights.dashboard.aws_iam_user_dashboard",
   271                status: "blocked",
   272              },
   273              "aws_insights.container.dashboard_aws_iam_user_dashboard_anonymous_container_0":
   274                {
   275                  name: "aws_insights.container.dashboard_aws_iam_user_dashboard_anonymous_container_0",
   276                  // @ts-ignore
   277                  status: "blocked",
   278                },
   279            },
   280            inputs: {
   281              "input.foo": "bar",
   282            },
   283            variables: {
   284              foo: "bar",
   285            },
   286            search_path: ["some_schema"],
   287            start_time: "2022-10-27T14:43:57.79514+01:00",
   288            end_time: "2022-10-27T14:43:58.045925+01:00",
   289          },
   290        };
   291  
   292        const eventMigrator = new ExecutionCompleteSchemaMigrator();
   293        const migratedEvent = eventMigrator.toLatest(inputEvent);
   294  
   295        expect(migratedEvent).toEqual(inputEvent);
   296      });
   297  
   298      test("Unsupported schema", () => {
   299        const inputEvent: DashboardExecutionEventWithSchema = {
   300          // @ts-ignore
   301          schema_version: "20221010",
   302        };
   303  
   304        const eventMigrator = new ExecutionCompleteSchemaMigrator();
   305  
   306        expect(() => eventMigrator.toLatest(inputEvent)).toThrow(
   307          `Unsupported dashboard event schema ${inputEvent.schema_version}`
   308        );
   309      });
   310    });
   311  
   312    describe("snapshot data to execution_complete event", () => {
   313      test("Schema 20220614 to 20221222", () => {
   314        const inputSnapshot: DashboardSnapshot = {
   315          schema_version: EXECUTION_SCHEMA_VERSION_20220614,
   316          layout: {
   317            name: "aws_insights.dashboard.aws_iam_user_dashboard",
   318            panel_type: "dashboard",
   319            children: [
   320              {
   321                name: "aws_insights.container.dashboard_aws_iam_user_dashboard_anonymous_container_0",
   322                panel_type: "container",
   323              },
   324            ],
   325          },
   326          panels: {
   327            "aws_insights.dashboard.aws_iam_user_dashboard": {
   328              name: "aws_insights.dashboard.aws_iam_user_dashboard",
   329              panel_type: "dashboard",
   330              dashboard: "aws_insights.dashboard.aws_iam_user_dashboard",
   331              // @ts-ignore
   332              status: "ready",
   333            },
   334            "aws_insights.container.dashboard_aws_iam_user_dashboard_anonymous_container_0":
   335              {
   336                name: "aws_insights.container.dashboard_aws_iam_user_dashboard_anonymous_container_0",
   337                panel_type: "container",
   338                dashboard: "aws_insights.dashboard.aws_iam_user_dashboard",
   339                // @ts-ignore
   340                status: "ready",
   341              },
   342          },
   343          inputs: {
   344            "input.foo": "bar",
   345          },
   346          variables: {
   347            foo: "bar",
   348          },
   349          search_path: ["some_schema"],
   350          start_time: "2022-10-27T14:43:57.79514+01:00",
   351          end_time: "2022-10-27T14:43:58.045925+01:00",
   352        };
   353  
   354        const eventMigrator = new SnapshotDataToExecutionCompleteSchemaMigrator();
   355        const migratedEvent = eventMigrator.toLatest(inputSnapshot);
   356  
   357        const expectedPanels = {
   358          "aws_insights.dashboard.aws_iam_user_dashboard": {
   359            name: "aws_insights.dashboard.aws_iam_user_dashboard",
   360            panel_type: "dashboard",
   361            dashboard: "aws_insights.dashboard.aws_iam_user_dashboard",
   362            status: "running",
   363          },
   364          "aws_insights.container.dashboard_aws_iam_user_dashboard_anonymous_container_0":
   365            {
   366              name: "aws_insights.container.dashboard_aws_iam_user_dashboard_anonymous_container_0",
   367              panel_type: "container",
   368              dashboard: "aws_insights.dashboard.aws_iam_user_dashboard",
   369              status: "running",
   370            },
   371        };
   372  
   373        const expectedEvent = {
   374          action: DashboardActions.EXECUTION_COMPLETE,
   375          execution_id: "",
   376          schema_version: EXECUTION_COMPLETE_SCHEMA_VERSION_LATEST,
   377          snapshot: {
   378            schema_version: EXECUTION_COMPLETE_SCHEMA_VERSION_LATEST,
   379            layout: inputSnapshot.layout,
   380            panels: expectedPanels,
   381            inputs: inputSnapshot.inputs,
   382            variables: inputSnapshot.variables,
   383            search_path: inputSnapshot.search_path,
   384            start_time: inputSnapshot.start_time,
   385            end_time: inputSnapshot.end_time,
   386          },
   387        };
   388  
   389        expect(migratedEvent).toEqual(expectedEvent);
   390      });
   391  
   392      test("Schema 20220929 to 20221222", () => {
   393        const inputSnapshot: DashboardSnapshot = {
   394          schema_version: EXECUTION_SCHEMA_VERSION_20220929,
   395          layout: {
   396            name: "aws_insights.dashboard.aws_iam_user_dashboard",
   397            panel_type: "dashboard",
   398            children: [
   399              {
   400                name: "aws_insights.container.dashboard_aws_iam_user_dashboard_anonymous_container_0",
   401                panel_type: "container",
   402              },
   403            ],
   404          },
   405          panels: {
   406            "aws_insights.dashboard.aws_iam_user_dashboard": {
   407              name: "aws_insights.dashboard.aws_iam_user_dashboard",
   408              panel_type: "dashboard",
   409              dashboard: "aws_insights.dashboard.aws_iam_user_dashboard",
   410              // @ts-ignore
   411              status: "ready",
   412            },
   413            "aws_insights.container.dashboard_aws_iam_user_dashboard_anonymous_container_0":
   414              {
   415                name: "aws_insights.container.dashboard_aws_iam_user_dashboard_anonymous_container_0",
   416                panel_type: "container",
   417                dashboard: "aws_insights.dashboard.aws_iam_user_dashboard",
   418                // @ts-ignore
   419                status: "ready",
   420              },
   421          },
   422          inputs: {
   423            "input.foo": "bar",
   424          },
   425          variables: {
   426            foo: "bar",
   427          },
   428          search_path: ["some_schema"],
   429          start_time: "2022-10-27T14:43:57.79514+01:00",
   430          end_time: "2022-10-27T14:43:58.045925+01:00",
   431        };
   432  
   433        const eventMigrator = new SnapshotDataToExecutionCompleteSchemaMigrator();
   434        const migratedEvent = eventMigrator.toLatest(inputSnapshot);
   435  
   436        const expectedPanels = {
   437          "aws_insights.dashboard.aws_iam_user_dashboard": {
   438            name: "aws_insights.dashboard.aws_iam_user_dashboard",
   439            panel_type: "dashboard",
   440            dashboard: "aws_insights.dashboard.aws_iam_user_dashboard",
   441            status: "running",
   442          },
   443          "aws_insights.container.dashboard_aws_iam_user_dashboard_anonymous_container_0":
   444            {
   445              name: "aws_insights.container.dashboard_aws_iam_user_dashboard_anonymous_container_0",
   446              panel_type: "container",
   447              dashboard: "aws_insights.dashboard.aws_iam_user_dashboard",
   448              status: "running",
   449            },
   450        };
   451  
   452        const expectedEvent = {
   453          action: DashboardActions.EXECUTION_COMPLETE,
   454          execution_id: "",
   455          schema_version: EXECUTION_COMPLETE_SCHEMA_VERSION_LATEST,
   456          snapshot: {
   457            schema_version: EXECUTION_COMPLETE_SCHEMA_VERSION_LATEST,
   458            layout: inputSnapshot.layout,
   459            panels: expectedPanels,
   460            inputs: inputSnapshot.inputs,
   461            variables: inputSnapshot.variables,
   462            search_path: inputSnapshot.search_path,
   463            start_time: inputSnapshot.start_time,
   464            end_time: inputSnapshot.end_time,
   465          },
   466        };
   467  
   468        expect(migratedEvent).toEqual(expectedEvent);
   469      });
   470  
   471      test("Schema 20221222 to 20221222", () => {
   472        const inputSnapshot: DashboardSnapshot = {
   473          schema_version: EXECUTION_SCHEMA_VERSION_20221222,
   474          layout: {
   475            name: "aws_insights.dashboard.aws_iam_user_dashboard",
   476            panel_type: "dashboard",
   477            children: [
   478              {
   479                name: "aws_insights.container.dashboard_aws_iam_user_dashboard_anonymous_container_0",
   480                panel_type: "container",
   481              },
   482            ],
   483          },
   484          panels: {
   485            "aws_insights.dashboard.aws_iam_user_dashboard": {
   486              name: "aws_insights.dashboard.aws_iam_user_dashboard",
   487              panel_type: "dashboard",
   488              dashboard: "aws_insights.dashboard.aws_iam_user_dashboard",
   489              status: "blocked",
   490            },
   491            "aws_insights.container.dashboard_aws_iam_user_dashboard_anonymous_container_0":
   492              {
   493                name: "aws_insights.container.dashboard_aws_iam_user_dashboard_anonymous_container_0",
   494                panel_type: "container",
   495                dashboard: "aws_insights.dashboard.aws_iam_user_dashboard",
   496                status: "blocked",
   497              },
   498          },
   499          inputs: {
   500            "input.foo": "bar",
   501          },
   502          variables: {
   503            foo: "bar",
   504          },
   505          search_path: ["some_schema"],
   506          start_time: "2022-10-27T14:43:57.79514+01:00",
   507          end_time: "2022-10-27T14:43:58.045925+01:00",
   508        };
   509  
   510        const eventMigrator = new SnapshotDataToExecutionCompleteSchemaMigrator();
   511        const migratedEvent = eventMigrator.toLatest(inputSnapshot);
   512  
   513        const expectedEvent = {
   514          action: DashboardActions.EXECUTION_COMPLETE,
   515          execution_id: "",
   516          schema_version: EXECUTION_COMPLETE_SCHEMA_VERSION_LATEST,
   517          snapshot: {
   518            schema_version: EXECUTION_COMPLETE_SCHEMA_VERSION_LATEST,
   519            layout: inputSnapshot.layout,
   520            panels: inputSnapshot.panels,
   521            inputs: inputSnapshot.inputs,
   522            variables: inputSnapshot.variables,
   523            search_path: inputSnapshot.search_path,
   524            start_time: inputSnapshot.start_time,
   525            end_time: inputSnapshot.end_time,
   526          },
   527        };
   528  
   529        expect(migratedEvent).toEqual(expectedEvent);
   530      });
   531  
   532      test("Unsupported schema", () => {
   533        const inputSnapshot: DashboardSnapshot = {
   534          // @ts-ignore
   535          schema_version: "20221010",
   536        };
   537  
   538        const eventMigrator = new SnapshotDataToExecutionCompleteSchemaMigrator();
   539  
   540        expect(() => eventMigrator.toLatest(inputSnapshot)).toThrow(
   541          `Unsupported dashboard event schema ${inputSnapshot.schema_version}`
   542        );
   543      });
   544    });
   545  });