Skip to content

Commit

Permalink
fixed types in all tests
Browse files Browse the repository at this point in the history
this pr should fix all types in every testcase that was previously throwing a compile error due to type miss matching

local test passed but i wasn't able to test the integration tests so please run them through GH actions to see if everything still works properly
  • Loading branch information
Enubia committed Jun 7, 2021
1 parent 90f8f11 commit 3b32c74
Show file tree
Hide file tree
Showing 14 changed files with 93 additions and 86 deletions.
16 changes: 10 additions & 6 deletions src/engine/action/Action.spec.ts
@@ -1,15 +1,15 @@
/* eslint-disable @typescript-eslint/no-empty-function */
/* eslint-disable @typescript-eslint/explicit-function-return-type */

import { Action, isAction, ACTION_TYPE_QUERY } from './Action';
import { Action, isAction, ACTION_TYPE_QUERY, ActionPreProcessor, ActionPostProcessor } from './Action';
import { Permission, isPermission } from '../permission/Permission';

import { DataTypeString, DataTypeInteger } from '../datatype/dataTypes';
import { buildObjectDataType } from '../datatype/ObjectDataType';

import { passOrThrow } from '../util';
import { generateTestSchema } from '../../graphqlProtocol/test-helper';
import { generateGraphQLSchema } from '../../graphqlProtocol/generator';
import { generateGraphQLSchema } from '../../graphqlProtocol';
import { graphql } from 'graphql';

describe('Action', () => {
Expand All @@ -27,6 +27,7 @@ describe('Action', () => {
// eslint-disable-next-line no-new
new Action({
name: 'example',
resolve: () => {}
});
}

Expand Down Expand Up @@ -54,6 +55,7 @@ describe('Action', () => {
description: 'do something',
input: 123,
output: 456,
resolve() {}
});
}

Expand Down Expand Up @@ -81,6 +83,7 @@ describe('Action', () => {
name: 'example',
description: 'do something',
input() {},
resolve() {},
output: 'wrong',
});
}
Expand Down Expand Up @@ -175,6 +178,7 @@ describe('Action', () => {
new Action({
name: 'example',
description: 'do something',
resolve: undefined as () => any
});
}

Expand Down Expand Up @@ -350,7 +354,7 @@ describe('Action', () => {
name: 'example',
description: 'do something',
resolve() {},
preProcessor: 'not-a-func',
preProcessor: ('not-a-func' as unknown) as ActionPreProcessor,
});
}

Expand Down Expand Up @@ -427,7 +431,7 @@ describe('Action', () => {
name: 'example',
description: 'do something',
resolve() {},
postProcessor: 'not-a-func',
postProcessor: ('not-a-func' as unknown) as ActionPostProcessor,
});
}

Expand Down Expand Up @@ -460,8 +464,8 @@ describe('Action', () => {
};
},
postProcessor: ({ result, input }) => {
if (input > 1000) {
result.value *= 2;
if ((input as any) > 1000) {
(result as any).value *= 2;
}
},
}),
Expand Down
2 changes: 1 addition & 1 deletion src/engine/entity/Entity.spec.ts
Expand Up @@ -17,7 +17,7 @@ import { Permission, isPermission } from '../permission/Permission';
import { passOrThrow } from '../util';
import { DataTypeID, DataTypeString } from '../datatype/dataTypes';

import { generateGraphQLSchema } from '../../graphqlProtocol/generator';
import { generateGraphQLSchema } from '../../graphqlProtocol';
import { generateTestSchema } from '../../graphqlProtocol/test-helper';

describe('Entity', () => {
Expand Down
3 changes: 2 additions & 1 deletion src/engine/entity/ViewEntity.spec.ts
Expand Up @@ -3,6 +3,7 @@ import { ViewEntity, isViewEntity } from './ViewEntity';
import { Permission, isPermission } from '../permission/Permission';
import { passOrThrow } from '../util';
import { DataTypeID, DataTypeString } from '../datatype/dataTypes';
import { StorageType } from '../storage/StorageType';

describe('ViewEntity', () => {
it('should have a name', () => {
Expand Down Expand Up @@ -159,7 +160,7 @@ describe('ViewEntity', () => {
description: 'ID of item',
},
},
storageType: {},
storageType: {} as StorageType,
});
}

Expand Down
5 changes: 2 additions & 3 deletions src/engine/filter.spec.ts
@@ -1,4 +1,3 @@
/* eslint-disable @typescript-eslint/camelcase */
/* eslint-disable @typescript-eslint/no-empty-function */
/* eslint-disable @typescript-eslint/explicit-function-return-type */

Expand Down Expand Up @@ -165,11 +164,11 @@ describe('filter', () => {

it('should throw if provided params are invalid', () => {
function fn1() {
validateFilterLevel();
validateFilterLevel(undefined, undefined, undefined, undefined);
}

function fn2() {
validateFilterLevel([], null, []);
validateFilterLevel([], null, [], undefined);
}

function fn3() {
Expand Down
6 changes: 3 additions & 3 deletions src/engine/index/Index.spec.ts
Expand Up @@ -63,7 +63,7 @@ describe('Index', () => {
// eslint-disable-next-line no-new
new Index({
type: INDEX_UNIQUE,
attributes: [123],
attributes: [((123 as unknown) as string)],
});
}

Expand Down Expand Up @@ -146,7 +146,7 @@ describe('Index', () => {
};

function fn() {
processEntityIndexes(entity, indexes);
processEntityIndexes(entity, (indexes as unknown) as Index[]);
}

expect(fn).toThrowErrorMatchingSnapshot();
Expand All @@ -156,7 +156,7 @@ describe('Index', () => {
const indexes = [{ foo: 'bar' }];

function fn() {
processEntityIndexes(entity, indexes);
processEntityIndexes(entity, (indexes as unknown) as Index[]);
}

expect(fn).toThrowErrorMatchingSnapshot();
Expand Down
56 changes: 28 additions & 28 deletions src/engine/permission/Permission.spec.ts
Expand Up @@ -16,7 +16,7 @@ import {
buildPermissionFilter,
buildLookupsPermissionFilter,
processEntityPermissions,
processActionPermissions,
processActionPermissions, PermissionMap,
} from './Permission';
import { Entity } from '../entity/Entity';
import { Action } from '../action/Action';
Expand Down Expand Up @@ -100,7 +100,7 @@ describe('Permission', () => {
describe('role permissions', () => {
it('should reject if role name is missing', () => {
function fn1() {
new Permission().role();
new Permission().role((undefined as unknown) as string);
}

expect(fn1).toThrowErrorMatchingSnapshot();
Expand All @@ -118,7 +118,7 @@ describe('Permission', () => {
describe('userAttribute permissions', () => {
it('should reject if attribute name is missing', () => {
function fn1() {
new Permission().userAttribute();
new Permission().userAttribute((undefined as unknown) as string);
}

expect(fn1).toThrowErrorMatchingSnapshot();
Expand All @@ -136,15 +136,15 @@ describe('Permission', () => {
describe('lookup permissions', () => {
it('should reject if entity is missing', () => {
function fn1() {
new Permission().lookup();
new Permission().lookup((undefined as unknown) as Entity, undefined);
}

expect(fn1).toThrowErrorMatchingSnapshot();
});

it('should reject if lookupMap is missing', () => {
function fn1() {
new Permission().lookup(Language);
new Permission().lookup(Language, undefined);
}

expect(fn1).toThrowErrorMatchingSnapshot();
Expand All @@ -154,15 +154,15 @@ describe('Permission', () => {
describe('value permissions', () => {
it('should reject if attribute name is missing', () => {
function fn1() {
new Permission().value();
new Permission().value((undefined as unknown) as string, undefined);
}

expect(fn1).toThrowErrorMatchingSnapshot();
});

it('should reject if value is missing', () => {
function fn1() {
new Permission().value('someAttribute');
new Permission().value('someAttribute', undefined);
}

expect(fn1).toThrowErrorMatchingSnapshot();
Expand Down Expand Up @@ -218,17 +218,17 @@ describe('Permission', () => {

function fn() {
passOrThrow(
isPermissionsArray() ||
isPermissionsArray(undefined) ||
isPermissionsArray(null) ||
isPermissionsArray([]) ||
isPermissionsArray({}) ||
isPermissionsArray(function test() {}) ||
isPermissionsArray(Error) ||
isPermissionsArray([{}]) ||
isPermissionsArray([function test() {}]) ||
isPermissionsArray([Error]) ||
isPermissionsArray(({} as unknown) as Permission) ||
isPermissionsArray((function test() {} as unknown) as Permission[]) ||
isPermissionsArray((Error as unknown) as Permission[]) ||
isPermissionsArray(([{}] as unknown) as Permission[]) ||
isPermissionsArray(([function test() {}] as unknown) as Permission[]) ||
isPermissionsArray(([Error] as unknown) as Permission[]) ||
isPermissionsArray([permission, null]) ||
isPermissionsArray([permission, {}, permission]),
isPermissionsArray([permission, {} as Permission, permission]),
() => 'Not a Permissions array',
);
}
Expand Down Expand Up @@ -363,7 +363,7 @@ describe('Permission', () => {
describe('permissions description', () => {
it('should reject if non-Permission object is provided', () => {
function fn() {
generatePermissionDescription({ foo: 'bar' });
generatePermissionDescription(({ foo: 'bar' } as unknown) as Permission);
}

expect(fn).toThrowErrorMatchingSnapshot();
Expand Down Expand Up @@ -430,15 +430,15 @@ describe('Permission', () => {

it('should reject if non-Permission object is provided', () => {
function fn() {
checkPermissionSimple({});
checkPermissionSimple({} as Permission);
}

expect(fn).toThrowErrorMatchingSnapshot();
});

it('should reject if user roles are not provided as an array', () => {
function fn() {
checkPermissionSimple(new Permission(), null, { bad: 'roles' });
checkPermissionSimple(new Permission(), null, ({ bad: 'roles' } as unknown) as any[]);
}

expect(fn).toThrowErrorMatchingSnapshot();
Expand Down Expand Up @@ -521,7 +521,7 @@ describe('Permission', () => {
function fn() {
const permission = new Permission().userAttribute('author');

buildUserAttributesPermissionFilter({ permission });
buildUserAttributesPermissionFilter({ permission, userId: undefined });
}

expect(fn).toThrowErrorMatchingSnapshot();
Expand Down Expand Up @@ -569,7 +569,7 @@ describe('Permission', () => {
function fn() {
const permission = new Permission().state('completed');

buildStatesPermissionFilter({ permission });
buildStatesPermissionFilter({ permission, entity: undefined });
}

expect(fn).toThrowErrorMatchingSnapshot();
Expand Down Expand Up @@ -913,7 +913,7 @@ describe('Permission', () => {
const permissions = ['bad'];

function fn() {
processEntityPermissions(entity, permissions);
processEntityPermissions(entity, (permissions as unknown) as PermissionMap);
}

expect(fn).toThrowErrorMatchingSnapshot();
Expand All @@ -925,7 +925,7 @@ describe('Permission', () => {
};

function fn() {
processEntityPermissions(entity, permissions);
processEntityPermissions(entity, (permissions as unknown) as PermissionMap);
}

expect(fn).toThrowErrorMatchingSnapshot();
Expand All @@ -937,7 +937,7 @@ describe('Permission', () => {
};

function fn() {
processEntityPermissions(entity, permissions);
processEntityPermissions(entity, (permissions as unknown) as PermissionMap);
}

expect(fn).toThrowErrorMatchingSnapshot();
Expand All @@ -949,7 +949,7 @@ describe('Permission', () => {
};

function fn1() {
processEntityPermissions(entity, permissions1);
processEntityPermissions(entity, (permissions1 as unknown) as PermissionMap);
}

expect(fn1).toThrowErrorMatchingSnapshot();
Expand All @@ -959,7 +959,7 @@ describe('Permission', () => {
};

function fn2() {
processEntityPermissions(entity, permissions2);
processEntityPermissions(entity, (permissions2 as unknown) as PermissionMap);
}

expect(fn2).toThrowErrorMatchingSnapshot();
Expand All @@ -973,7 +973,7 @@ describe('Permission', () => {
};

function fn3() {
processEntityPermissions(entity, permissions3);
processEntityPermissions(entity, (permissions3 as unknown) as PermissionMap);
}

expect(fn3).toThrowErrorMatchingSnapshot();
Expand Down Expand Up @@ -1121,7 +1121,7 @@ describe('Permission', () => {
const permissions1 = ['bad'];

function fn1() {
processActionPermissions(action, permissions1);
processActionPermissions(action, (permissions1 as unknown) as Permission[]);
}

expect(fn1).toThrowErrorMatchingSnapshot();
Expand All @@ -1131,7 +1131,7 @@ describe('Permission', () => {
};

function fn2() {
processActionPermissions(action, permissions2);
processActionPermissions(action, (permissions2 as unknown) as Permission[]);
}

expect(fn2).toThrowErrorMatchingSnapshot();
Expand Down
9 changes: 5 additions & 4 deletions src/engine/protocol/ProtocolType.spec.ts
@@ -1,12 +1,13 @@
/* eslint-disable @typescript-eslint/explicit-function-return-type */

import { ProtocolType, isProtocolType } from './ProtocolType';
import { ProtocolType, isProtocolType, ProtocolDataType } from './ProtocolType';
import {
DataTypeID,
DataTypeString,
DataTypeInteger,
DataTypeBoolean,
} from '../datatype/dataTypes';
import { DataType } from '../datatype/DataType';

describe('ProtocolType', () => {
const ProtocolTypeREST = new ProtocolType({
Expand Down Expand Up @@ -80,15 +81,15 @@ describe('ProtocolType', () => {

it('should reject invalid data type mappings', () => {
function fn1() {
ProtocolTypeREST.addDataTypeMap('something');
ProtocolTypeREST.addDataTypeMap(('something' as unknown) as DataType, undefined);
}

function fn2() {
ProtocolTypeREST.addDataTypeMap(DataTypeID);
ProtocolTypeREST.addDataTypeMap(DataTypeID, undefined);
}

function fn3() {
ProtocolTypeREST.addDataTypeMap(DataTypeString, {});
ProtocolTypeREST.addDataTypeMap(DataTypeString, ({} as unknown) as ProtocolDataType);
}

expect(fn1).toThrowErrorMatchingSnapshot();
Expand Down

0 comments on commit 3b32c74

Please sign in to comment.