Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue 70 delete account runtime exception #71

Merged
merged 3 commits into from
May 27, 2024
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
1 change: 1 addition & 0 deletions src/dal/entity/event.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export class Event extends ShareableId {
@ManyToOne({
entity: () => User,
fieldName: 'createdByUserId',
onDelete: 'cascade',
wrappedReference: true
})
public createdBy!: IdentifiedReference<User>;
Expand Down
1 change: 1 addition & 0 deletions src/dal/migrations/postgres/.snapshot-postgres.json
Original file line number Diff line number Diff line change
Expand Up @@ -1175,6 +1175,7 @@
"id"
],
"referencedTableName": "public.user",
"deleteRule": "cascade",
"updateRule": "cascade"
},
"event_cover_image_id_foreign": {
Expand Down
17 changes: 17 additions & 0 deletions src/dal/migrations/postgres/Migration20240526235049.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { Migration } from '@mikro-orm/migrations';

export class Migration20240526235049 extends Migration {

async up(): Promise<void> {
this.addSql('alter table "event" drop constraint "event_createdByUserId_foreign";');

this.addSql('alter table "event" add constraint "event_createdByUserId_foreign" foreign key ("createdByUserId") references "user" ("id") on update cascade on delete cascade;');
}

async down(): Promise<void> {
this.addSql('alter table "event" drop constraint "event_createdByUserId_foreign";');

this.addSql('alter table "event" add constraint "event_createdByUserId_foreign" foreign key ("createdByUserId") references "user" ("id") on update cascade;');
}

}
17 changes: 17 additions & 0 deletions src/dal/migrations/sqlite/Migration20240527000623.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { Migration } from '@mikro-orm/migrations';

export class Migration20240527000623 extends Migration {

async up(): Promise<void> {
this.addSql('PRAGMA foreign_keys = OFF;');
this.addSql('CREATE TABLE `_knex_temp_alter256` (`id` integer PRIMARY KEY AUTOINCREMENT NOT NULL, `shareableId` text NOT NULL, `name` text NOT NULL, `description` text NULL, `createdByUserId` integer NOT NULL, `start_date_time` text NULL, `end_date_time` text NULL, `image` text NULL, `latitude` real NULL, `longitude` real NULL, `location_label` text NULL, `flagged` integer NULL, `banned` integer NULL, `hub_id` integer NULL CONSTRAINT `event_hub_id_foreign` REFERENCES `hub` (`id`) ON DELETE SET NULL ON UPDATE CASCADE, `cover_image_id` integer NULL CONSTRAINT `event_cover_image_id_foreign` REFERENCES `file` (`id`) ON DELETE SET NULL ON UPDATE CASCADE, `minimum_capacity` real NULL, `maximum_capacity` real NULL, CONSTRAINT `event_createdByUserId_foreign` FOREIGN KEY (`createdByUserId`) REFERENCES `user` (`id`) ON UPDATE CASCADE, CONSTRAINT `event_createdByUserId_foreign` FOREIGN KEY (`createdByUserId`) REFERENCES `user` (`id`) ON DELETE cascade ON UPDATE cascade);');
this.addSql('INSERT INTO "_knex_temp_alter256" SELECT * FROM "event";;');
this.addSql('DROP TABLE "event";');
this.addSql('ALTER TABLE "_knex_temp_alter256" RENAME TO "event";');
this.addSql('CREATE INDEX `event_createdByUserId_index` on `event` (`createdByUserId`);');
this.addSql('CREATE INDEX `event_hub_id_index` on `event` (`hub_id`);');
this.addSql('CREATE INDEX `event_cover_image_id_index` on `event` (`cover_image_id`);');
this.addSql('PRAGMA foreign_keys = ON;');
}

}
69 changes: 69 additions & 0 deletions test/app.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ describe('AppController (e2e)', () => {
},
})
.expect(200);

expect(result.body?.data?.createHub?.hub).toBeDefined();
expect(result.body?.data?.createHub?.hubId).toBeDefined();
hubId = result.body?.data?.createHub?.hubId;
Expand Down Expand Up @@ -391,6 +392,73 @@ describe('AppController (e2e)', () => {
expect(result.body?.data?.deleteHub).toBeDefined();
});

it('/graphql createEvent', async () => {
const result = await request(app.getHttpServer())
.post('/graphql')
.set({ authorization: `Bearer ${token}` })
.send({
operationName: null,
query: `mutation createEvent(
$name: String!
$hubId: String
$description: String
$startDateTime: String
$endDateTime: String
$minimumCapacity: Int
$maximumCapacity: Int
$latitude: Float
$longitude: Float
$locationLabel: String
$imageFile: Upload
) {
createEvent(
name: $name
hubId: $hubId
description: $description
startDateTime: $startDateTime
endDateTime: $endDateTime
minimumCapacity: $minimumCapacity
maximumCapacity: $maximumCapacity
latitude: $latitude
longitude: $longitude
locationLabel: $locationLabel
imageFile: $imageFile
) {
userId
eventId
user {
id
firstName
lastName
description
image
email
shareableId
}
event {
id
name
description
startDateTime
endDateTime
latitude
longitude
shareableId
}
rsvp
lastGeofenceEvent
lastUpdated
}
}`,
variables: {
name: 'test event',
},
})
.expect(200);

expect(result.body?.data?.createEvent).toBeDefined();
});

it('/graphql deleteAccount', async () => {
const result = await request(app.getHttpServer())
.post('/graphql')
Expand All @@ -414,5 +482,6 @@ describe('AppController (e2e)', () => {
.expect(200);

expect(result.body?.data?.deleteAccount).toBeDefined();
return result;
});
});
Loading