-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(moderation): add procedures validate external test
- Loading branch information
1 parent
2ccca91
commit 25261c6
Showing
1 changed file
with
88 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,26 +36,78 @@ setDatabaseConnection(client as any); | |
// | ||
|
||
beforeAll(migrate); | ||
beforeAll(() => setSystemTime(new Date("2222-01-01T00:00:00.000Z"))); | ||
beforeEach(() => setSystemTime(new Date("2222-01-01T00:00:00.000Z"))); | ||
beforeEach(empty_database); | ||
|
||
test("GET /moderation/:id/$procedures/validate", async () => { | ||
const unicorn_organization_id = await create_unicorn_organization(pg); | ||
const adora_pony_user_id = await create_adora_pony_user(pg); | ||
test("GET /moderation/:id/$procedures/validate { add_domain: true, add_member: AS_INTERNAL }", async () => { | ||
const { adora_pony_user_id, moderation_id, unicorn_organization_id } = | ||
await given_moderation_42(); | ||
|
||
const body = new FormData(); | ||
body.append("add_domain", "true"); | ||
body.append("add_member", FORM_SCHEMA.shape.add_member.Enum.AS_INTERNAL); | ||
const response = await new Hono() | ||
.use(set_config({})) | ||
.use(set_moncomptepro_pg(pg)) | ||
.use(set_nonce("nonce")) | ||
.use(set_userinfo(anais_tailhade)) | ||
.route("/:id", app) | ||
.onError((error) => { | ||
throw error; | ||
}) | ||
.request(`/${moderation_id}`, { method: "PATCH", body }); | ||
|
||
expect(response.status).toBe(200); | ||
|
||
await pg.insert(schema.moderations).values({ | ||
id: 42, | ||
expect( | ||
await pg.query.moderations.findFirst({ | ||
where: (table, { eq }) => eq(table.id, moderation_id), | ||
}), | ||
).toEqual({ | ||
id: moderation_id, | ||
organization_id: unicorn_organization_id, | ||
user_id: adora_pony_user_id, | ||
type: "", | ||
ticket_id: null, | ||
moderated_at: "2222-01-02 00:00:00+00", | ||
moderated_by: "[email protected]", | ||
comment: | ||
"7952428800000 [email protected] | Validé par [email protected] ", | ||
created_at: "2222-01-01 00:00:00+00", | ||
}); | ||
|
||
const body = new FormData(); | ||
body.append("add_domain", "true"); | ||
body.append("add_member", FORM_SCHEMA.shape.add_member.Enum.AS_INTERNAL); | ||
expect( | ||
await pg.query.users_organizations.findFirst({ | ||
where: (table, { and, eq }) => | ||
and( | ||
eq(table.organization_id, unicorn_organization_id), | ||
eq(table.user_id, adora_pony_user_id), | ||
), | ||
}), | ||
).toEqual({ | ||
authentication_by_peers_type: null, | ||
created_at: "2222-01-02 00:00:00+00", | ||
has_been_greeted: false, | ||
is_external: false, | ||
needs_official_contact_email_verification: false, | ||
official_contact_email_verification_sent_at: null, | ||
official_contact_email_verification_token: null, | ||
organization_id: unicorn_organization_id, | ||
sponsor_id: null, | ||
updated_at: "2222-01-02 00:00:00+00", | ||
user_id: adora_pony_user_id, | ||
verification_type: "domain", | ||
verified_at: null, | ||
}); | ||
}); | ||
|
||
setSystemTime(new Date("2222-01-02T00:00:00.000Z")); | ||
test("GET /moderation/:id/$procedures/validate { add_domain: false, add_member: AS_EXTERNAL }", async () => { | ||
const { adora_pony_user_id, moderation_id, unicorn_organization_id } = | ||
await given_moderation_42(); | ||
|
||
const body = new FormData(); | ||
body.append("add_domain", "false"); | ||
body.append("add_member", FORM_SCHEMA.shape.add_member.Enum.AS_EXTERNAL); | ||
const response = await new Hono() | ||
.use(set_config({})) | ||
.use(set_moncomptepro_pg(pg)) | ||
|
@@ -65,16 +117,16 @@ test("GET /moderation/:id/$procedures/validate", async () => { | |
.onError((error) => { | ||
throw error; | ||
}) | ||
.request("/42", { method: "PATCH", body }); | ||
.request(`/${moderation_id}`, { method: "PATCH", body }); | ||
|
||
expect(response.status).toBe(200); | ||
|
||
expect( | ||
await pg.query.moderations.findFirst({ | ||
where: (table, { eq }) => eq(table.id, 42), | ||
where: (table, { eq }) => eq(table.id, moderation_id), | ||
}), | ||
).toEqual({ | ||
id: 42, | ||
id: moderation_id, | ||
organization_id: unicorn_organization_id, | ||
user_id: adora_pony_user_id, | ||
type: "", | ||
|
@@ -98,7 +150,7 @@ test("GET /moderation/:id/$procedures/validate", async () => { | |
authentication_by_peers_type: null, | ||
created_at: "2222-01-02 00:00:00+00", | ||
has_been_greeted: false, | ||
is_external: false, | ||
is_external: true, | ||
needs_official_contact_email_verification: false, | ||
official_contact_email_verification_sent_at: null, | ||
official_contact_email_verification_token: null, | ||
|
@@ -110,3 +162,25 @@ test("GET /moderation/:id/$procedures/validate", async () => { | |
verified_at: null, | ||
}); | ||
}); | ||
|
||
async function given_moderation_42() { | ||
const unicorn_organization_id = await create_unicorn_organization(pg); | ||
const adora_pony_user_id = await create_adora_pony_user(pg); | ||
|
||
const [{ id: moderation_id }] = await pg | ||
.insert(schema.moderations) | ||
.values({ | ||
organization_id: unicorn_organization_id, | ||
user_id: adora_pony_user_id, | ||
type: "", | ||
}) | ||
.returning({ id: schema.moderations.id }); | ||
|
||
setSystemTime(new Date("2222-01-02T00:00:00.000Z")); | ||
|
||
return { | ||
adora_pony_user_id, | ||
moderation_id, | ||
unicorn_organization_id, | ||
}; | ||
} |