Skip to content

Commit

Permalink
Merge pull request #4 from amplication/fix/tests
Browse files Browse the repository at this point in the history
Fix/tests
  • Loading branch information
abrl91 authored Apr 4, 2024
2 parents 5f964e5 + 7074609 commit 29bc6c1
Show file tree
Hide file tree
Showing 15 changed files with 339 additions and 2,772 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/dsg-e2e-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ jobs:
- name: Run generated code
run: |
cd test-cases/${{ matrix.test-cases }}/generated/server
npm run compose:up
docker-compose up -d
- name: Run e2e tests
run: npm run e2e:test
Expand Down
88 changes: 72 additions & 16 deletions main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import {
authBasic,
postgres,
authJWT,
auth0,
authSAML,
mysql,
} from "./test-data/plugins";
Expand All @@ -26,46 +25,103 @@ import {
EnumDataType,
EnumResourceType,
} from "@amplication/code-gen-types/src/models";
import { cloneDeep } from "lodash";

const pluginCombinations: Record<PluginCombinationName, PluginInstallation[]> =
{
[PluginCombinationName.POSTGRES_NO_AUTH]: [postgres],
[PluginCombinationName.POSTGRES_BASIC]: [postgres, authCore, authBasic],
[PluginCombinationName.POSTGRES_JWT]: [postgres, authCore, authJWT],
[PluginCombinationName.POSTGRES_AUTH0]: [postgres, authCore, auth0],
[PluginCombinationName.POSTGRES_SAML]: [postgres, authSAML],
[PluginCombinationName.MYSQL_NO_AUTH]: [mysql],
[PluginCombinationName.MYSQL_BASIC]: [mysql, authCore, authBasic],
[PluginCombinationName.MYSQL_JWT]: [mysql, authCore, authJWT],
[PluginCombinationName.MYSQL_AUTH0]: [mysql, authCore, auth0],
};

const baseDsgResourceData: DSGResourceData = {
buildId: "1",
entities,
roles,
resourceInfo,
resourceType: EnumResourceType.Service,
pluginInstallations:
pluginCombinations[PluginCombinationName.POSTGRES_NO_AUTH],
moduleActions: customActions,
moduleContainers,
moduleDtos,
};

function handlePluginCases(plugins: PluginInstallation[]): DSGResourceData {
let mockedEntities = cloneDeep(entities);
let mockedResourceInfo = cloneDeep(resourceInfo);
// remove entity field types that are not supported by mysql
if (plugins.some((plugin) => plugin === mysql)) {
console.log(
plugins,
"remove entity field types that are not supported by mysql"
);
mockedEntities = mockedEntities.map((entity) => {
entity.fields = entity.fields.filter(
(field) => field.dataType !== EnumDataType.MultiSelectOptionSet
);
return entity;
});
}

// when SAML is installed, add sessionId field to auth entity
if (plugins.some((plugin) => plugin === authSAML)) {
const authEntityName = resourceInfo.settings.authEntityName;
const sessionIdField = {
id: "22c4a27a-6490-4fb8-b951-7f42ded681bc",
permanentId: "22c4a27a-6490-4fb8-b951-7f42ded681b1",
name: "sessionId",
displayName: "sessionId",
dataType: EnumDataType.SingleLineText,
properties: {},
required: true,
unique: true,
searchable: false,
};

mockedEntities = mockedEntities.map((entity) => {
if (entity.name === authEntityName) {
entity.fields.push(sessionIdField);
}
return entity;
});
}

if (
!plugins.some((plugin) => plugin === authCore) &&
!plugins.some((plugin) => plugin === authSAML)
) {
mockedResourceInfo.settings.authEntityName = "";
}

return {
...baseDsgResourceData,
entities: mockedEntities,
resourceInfo: mockedResourceInfo,
};
}

/**
* Generates test config for each test case from the plugin combinations
* Taking care of case such as when MySQL is installed, creating entities without multi-select option data type
* @returns the test config for each test case
*/
function createTestConfig(): TestConfig[] {
const results = Object.entries(pluginCombinations).map(([name, plugins]) => {
let mockEntities = entities;

// remove entity field types that are not supported by mysql
if (plugins.find((plugin) => plugin.npm.indexOf("plugin-db-mysql"))) {
mockEntities = entities.map((entity) => {
entity.fields = entity.fields.filter(
(field) => field.dataType !== EnumDataType.MultiSelectOptionSet
);
return entity;
});
}
const { entities: changedEntities, resourceInfo: changedResourceInfo } =
handlePluginCases(plugins);

return {
name: name as PluginCombinationName,
data: {
buildId: "1",
entities: mockEntities,
entities: changedEntities,
roles,
resourceInfo,
resourceInfo: changedResourceInfo,
resourceType: EnumResourceType.Service,
pluginInstallations: plugins,
moduleActions: customActions,
Expand Down
2 changes: 0 additions & 2 deletions test-cases/mysql-auth0/dsg.env

This file was deleted.

Loading

0 comments on commit 29bc6c1

Please sign in to comment.