|
|
@@ -69,11 +69,25 @@ class TestResolver {
|
|
|
constructor(private testAdminService: TestAdminService, private connection: TransactionalConnection) {}
|
|
|
|
|
|
@Mutation()
|
|
|
- @Transaction
|
|
|
+ @Transaction()
|
|
|
createTestAdministrator(@Ctx() ctx: RequestContext, @Args() args: any) {
|
|
|
return this.testAdminService.createAdministrator(ctx, args.emailAddress, args.fail);
|
|
|
}
|
|
|
|
|
|
+ @Mutation()
|
|
|
+ @Transaction('manual')
|
|
|
+ async createTestAdministrator2(@Ctx() ctx: RequestContext, @Args() args: any) {
|
|
|
+ await this.connection.startTransaction(ctx);
|
|
|
+ return this.testAdminService.createAdministrator(ctx, args.emailAddress, args.fail);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Mutation()
|
|
|
+ @Transaction('manual')
|
|
|
+ async createTestAdministrator3(@Ctx() ctx: RequestContext, @Args() args: any) {
|
|
|
+ // no transaction started
|
|
|
+ return this.testAdminService.createAdministrator(ctx, args.emailAddress, args.fail);
|
|
|
+ }
|
|
|
+
|
|
|
@Query()
|
|
|
async verify() {
|
|
|
const admins = await this.connection.getRepository(Administrator).find();
|
|
|
@@ -92,6 +106,8 @@ class TestResolver {
|
|
|
schema: gql`
|
|
|
extend type Mutation {
|
|
|
createTestAdministrator(emailAddress: String!, fail: Boolean!): Administrator
|
|
|
+ createTestAdministrator2(emailAddress: String!, fail: Boolean!): Administrator
|
|
|
+ createTestAdministrator3(emailAddress: String!, fail: Boolean!): Administrator
|
|
|
}
|
|
|
type VerifyResult {
|
|
|
admins: [Administrator!]!
|
|
|
@@ -161,19 +177,82 @@ describe('Transaction infrastructure', () => {
|
|
|
expect(!!verify.admins.find((a: any) => a.emailAddress === 'test2')).toBe(false);
|
|
|
expect(!!verify.users.find((u: any) => u.identifier === 'test2')).toBe(false);
|
|
|
});
|
|
|
+
|
|
|
+ it('failing manual mutation', async () => {
|
|
|
+ try {
|
|
|
+ await adminClient.query(CREATE_ADMIN2, {
|
|
|
+ emailAddress: 'test3',
|
|
|
+ fail: true,
|
|
|
+ });
|
|
|
+ fail('Should have thrown');
|
|
|
+ } catch (e) {
|
|
|
+ expect(e.message).toContain('Failed!');
|
|
|
+ }
|
|
|
+
|
|
|
+ const { verify } = await adminClient.query(VERIFY_TEST);
|
|
|
+
|
|
|
+ expect(verify.admins.length).toBe(2);
|
|
|
+ expect(verify.users.length).toBe(2);
|
|
|
+ expect(!!verify.admins.find((a: any) => a.emailAddress === 'test3')).toBe(false);
|
|
|
+ expect(!!verify.users.find((u: any) => u.identifier === 'test3')).toBe(false);
|
|
|
+ });
|
|
|
+
|
|
|
+ it('failing manual mutation without transaction', async () => {
|
|
|
+ try {
|
|
|
+ await adminClient.query(CREATE_ADMIN3, {
|
|
|
+ emailAddress: 'test4',
|
|
|
+ fail: true,
|
|
|
+ });
|
|
|
+ fail('Should have thrown');
|
|
|
+ } catch (e) {
|
|
|
+ expect(e.message).toContain('Failed!');
|
|
|
+ }
|
|
|
+
|
|
|
+ const { verify } = await adminClient.query(VERIFY_TEST);
|
|
|
+
|
|
|
+ expect(verify.admins.length).toBe(2);
|
|
|
+ expect(verify.users.length).toBe(3);
|
|
|
+ expect(!!verify.admins.find((a: any) => a.emailAddress === 'test4')).toBe(false);
|
|
|
+ expect(!!verify.users.find((u: any) => u.identifier === 'test4')).toBe(true);
|
|
|
+ });
|
|
|
});
|
|
|
|
|
|
+const ADMIN_FRAGMENT = gql`
|
|
|
+ fragment CreatedAdmin on Administrator {
|
|
|
+ id
|
|
|
+ emailAddress
|
|
|
+ user {
|
|
|
+ id
|
|
|
+ identifier
|
|
|
+ }
|
|
|
+ }
|
|
|
+`;
|
|
|
+
|
|
|
const CREATE_ADMIN = gql`
|
|
|
mutation CreateTestAdmin($emailAddress: String!, $fail: Boolean!) {
|
|
|
createTestAdministrator(emailAddress: $emailAddress, fail: $fail) {
|
|
|
- id
|
|
|
- emailAddress
|
|
|
- user {
|
|
|
- id
|
|
|
- identifier
|
|
|
- }
|
|
|
+ ...CreatedAdmin
|
|
|
+ }
|
|
|
+ }
|
|
|
+ ${ADMIN_FRAGMENT}
|
|
|
+`;
|
|
|
+
|
|
|
+const CREATE_ADMIN2 = gql`
|
|
|
+ mutation CreateTestAdmin2($emailAddress: String!, $fail: Boolean!) {
|
|
|
+ createTestAdministrator2(emailAddress: $emailAddress, fail: $fail) {
|
|
|
+ ...CreatedAdmin
|
|
|
+ }
|
|
|
+ }
|
|
|
+ ${ADMIN_FRAGMENT}
|
|
|
+`;
|
|
|
+
|
|
|
+const CREATE_ADMIN3 = gql`
|
|
|
+ mutation CreateTestAdmin2($emailAddress: String!, $fail: Boolean!) {
|
|
|
+ createTestAdministrator3(emailAddress: $emailAddress, fail: $fail) {
|
|
|
+ ...CreatedAdmin
|
|
|
}
|
|
|
}
|
|
|
+ ${ADMIN_FRAGMENT}
|
|
|
`;
|
|
|
|
|
|
const VERIFY_TEST = gql`
|