Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
Warnings:

- You are about to drop the column `name` on the `TestExecution` table. All the data in the column will be lost.
- Added the required column `featureFile` to the `TestExecution` table without a default value. This is not possible if the table is not empty.
- Added the required column `testName` to the `TestExecution` table without a default value. This is not possible if the table is not empty.
- Added the required column `featureFile` to the `TestExecutionGroup` table without a default value. This is not possible if the table is not empty.
- Added the required column `testName` to the `TestExecutionGroup` table without a default value. This is not possible if the table is not empty.

*/
-- AlterTable
ALTER TABLE "TestExecution" DROP COLUMN "name",
ADD COLUMN "featureFile" TEXT NOT NULL,
ADD COLUMN "testName" TEXT NOT NULL;

-- AlterTable
ALTER TABLE "TestExecutionGroup" ADD COLUMN "featureFile" TEXT NOT NULL,
ADD COLUMN "testName" TEXT NOT NULL;
5 changes: 4 additions & 1 deletion prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,15 @@ model TestRun {

model TestExecutionGroup {
id String @id @default(uuid()) @db.Uuid
testName String
featureFile String
testExecutions TestExecution[]
}

model TestExecution {
id String @id @default(uuid()) @db.Uuid
name String
testName String
featureFile String
result TestStatus
at DateTime @default(now())
until DateTime?
Expand Down
2 changes: 2 additions & 0 deletions src/datasources/TestResults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@ export class TestResults {
__typename: 'TestExecutionStatus' as const,
testStatus,
testName,
featureFile: '',
rerunOfId: null,
id: testExecution.node.id,
};
}),
Expand Down
8 changes: 6 additions & 2 deletions src/repository/repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,11 @@ class PrismaRepository implements Repository {
});
}

async createTestExecution(args: TestExecution) {
async createTestExecution(
args: TestExecution,
testName: string,
featureFile: string,
) {
const { testExecutionGroupId, testRunId } = args;

const testExecutionGroup =
Expand All @@ -90,7 +94,7 @@ class PrismaRepository implements Repository {

if (!testExecutionGroup) {
await this.db.prisma.testExecutionGroup.create({
data: { id: testExecutionGroupId },
data: { id: testExecutionGroupId, testName, featureFile },
});
}

Expand Down
19 changes: 15 additions & 4 deletions src/resolvers/Mutation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ const resolvers: MutationResolvers = {
{ runID, testName, featureFile },
{ auth, repository },
): Promise<CreateTestExecutionResponse> => {
if (!auth) {
throw new Error('Failed to verify organisation details.');
}
const organisationIdentifier =
repository.getOrganisationIdentifier(auth);

Expand All @@ -85,7 +88,8 @@ const resolvers: MutationResolvers = {

const testExecution = {
id: testExecutionId,
name: testName,
testName: testName,
featureFile: featureFile,
result: TestStatus.InProgress,
at: new Date(),
until: null,
Expand All @@ -94,7 +98,12 @@ const resolvers: MutationResolvers = {
rerunOfId: null,
};

await repository.createTestExecution(testExecution);
await repository.createTestExecution(
testExecution,
testName,
featureFile,
);

return {
__typename: 'CreateTestExecutionResponse',
testExecutionId,
Expand Down Expand Up @@ -141,11 +150,13 @@ const resolvers: MutationResolvers = {
PrismaRunStatus.COMPLETED,
);
}

const { testName, featureFile, rerunOfId } = testExecution;
return {
__typename: 'TestExecutionStatus',
id: testExecutionId,
testName: testExecution.name,
testName,
featureFile,
rerunOfId,
testStatus,
};
},
Expand Down
25 changes: 16 additions & 9 deletions src/resolvers/Query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,15 +106,22 @@ const resolvers: QueryResolvers = {
}

const testExecutionStatuses = testRun.testExecutions.map(
(execution) => ({
__typename: 'TestExecutionStatus' as const,
id: execution.id,
testName: execution.name,
testStatus:
execution.result === PrismaTestStatus.PASSED
? TestStatus.Passed
: TestStatus.Failed,
}),
(execution) => {
const { id, testName, featureFile, rerunOfId, result } =
execution;

return {
__typename: 'TestExecutionStatus' as const,
id,
testName,
featureFile,
rerunOfId,
testStatus:
result === PrismaTestStatus.PASSED
? TestStatus.Passed
: TestStatus.Failed,
};
},
);

const runStatus =
Expand Down
2 changes: 2 additions & 0 deletions src/resolvers/TestExecutionStatus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { TestExecutionStatusResolvers } from './types/generated.js';
const resolvers: TestExecutionStatusResolvers = {
testStatus: ({ testStatus }) => testStatus,
testName: ({ testName }) => testName,
featureFile: ({ featureFile }) => featureFile,
rerunOfId: ({ rerunOfId }) => rerunOfId,
id: ({ id }) => id,
};

Expand Down
4 changes: 4 additions & 0 deletions src/resolvers/types/generated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -777,7 +777,9 @@ export type TestExecutionSnapshot = Event & InstantaneousEvent & TestExecutionEv

export type TestExecutionStatus = {
readonly __typename: 'TestExecutionStatus';
readonly featureFile: Scalars['String'];
readonly id: Scalars['ID'];
readonly rerunOfId: Maybe<Scalars['ID']>;
readonly testName: Scalars['String'];
readonly testStatus: TestStatus;
};
Expand Down Expand Up @@ -1632,7 +1634,9 @@ export type TestExecutionSnapshotResolvers<ContextType = Context, ParentType ext
};

export type TestExecutionStatusResolvers<ContextType = Context, ParentType extends ResolversParentTypes['TestExecutionStatus'] = ResolversParentTypes['TestExecutionStatus']> = {
featureFile: Resolver<ResolversTypes['String'], ParentType, ContextType>;
id: Resolver<ResolversTypes['ID'], ParentType, ContextType>;
rerunOfId: Resolver<Maybe<ResolversTypes['ID']>, ParentType, ContextType>;
testName: Resolver<ResolversTypes['String'], ParentType, ContextType>;
testStatus: Resolver<ResolversTypes['TestStatus'], ParentType, ContextType>;
__isTypeOf?: IsTypeOfResolverFn<ParentType, ContextType>;
Expand Down
2 changes: 2 additions & 0 deletions src/schema/execution/TestStatus.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ enum TestStatus {
type TestExecutionStatus {
id: ID!
testName: String!
featureFile: String!
testStatus: TestStatus!
rerunOfId: ID # This is not ideal and we'd like to return a TestExecution here
}

type TestRunStatus {
Expand Down
43 changes: 36 additions & 7 deletions src/seed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@ if (process.env.NODE_ENV === 'production') {
const prisma = new PrismaClient();

async function main() {
const user = await prisma.user.create({
data: {
email: 'testuser@example.com',
},
});
console.log('Created User: ', user);

const organisation = await prisma.organisation.create({
data: {
name: 'Testerloop',
Expand All @@ -25,6 +32,15 @@ async function main() {
},
});
console.log('Created Organisation: ', organisation);

const userOrganisation = await prisma.userOrganisation.create({
data: {
userId: user.id,
organisationId: organisation.id,
},
});
console.log('Created UserOrganisation: ', userOrganisation);

const testRun = await prisma.testRun.create({
data: {
status: RunStatus.COMPLETED,
Expand All @@ -39,19 +55,29 @@ async function main() {
});

const testExecutionGroup = await prisma.testExecutionGroup.create({
data: {},
data: {
testName: 'Test Name 1',
featureFile: 'Feature File 1',
},
});
const testExecutionGroup2 = await prisma.testExecutionGroup.create({
data: {},
data: {
testName: 'Test Name 2',
featureFile: 'Feature File 2',
},
});
const testExecutionGroup3 = await prisma.testExecutionGroup.create({
data: {},
data: {
testName: 'Test Name 3',
featureFile: 'Feature File 3',
},
});

const testExecution1 = await prisma.testExecution.create({
data: {
name: 'Test Execution 1',
testName: 'Test Execution 1',
result: TestStatus.FAILED,
featureFile: 'Feature File 1',
testRunId: testRun.id,
at: new Date(new Date().getTime() - 10 * 60000),
until: new Date(),
Expand All @@ -61,7 +87,8 @@ async function main() {

const testExecution2 = await prisma.testExecution.create({
data: {
name: 'Test Execution 1',
testName: 'Test Execution 1',
featureFile: 'Feature File 2',
result: TestStatus.PASSED,
testRunId: testRun.id,
testExecutionGroupId: testExecutionGroup.id,
Expand All @@ -72,7 +99,8 @@ async function main() {
});
const testExecution3 = await prisma.testExecution.create({
data: {
name: 'Test Execution 2',
testName: 'Test Execution 2',
featureFile: 'Feature File 3',
result: TestStatus.IN_PROGRESS,
testRunId: testRun2.id,
testExecutionGroupId: testExecutionGroup2.id,
Expand All @@ -81,7 +109,8 @@ async function main() {

const testExecution4 = await prisma.testExecution.create({
data: {
name: 'Test Execution 3',
testName: 'Test Execution 3',
featureFile: 'Feature File 3',
result: TestStatus.IN_PROGRESS,
testRunId: testRun2.id,
testExecutionGroupId: testExecutionGroup3.id,
Expand Down