Skip to content

Commit

Permalink
fix(server): link e2e user to its establishment
Browse files Browse the repository at this point in the history
  • Loading branch information
Falinor committed Aug 12, 2024
1 parent 0cb0a8a commit 0c7a012
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,21 @@ import { Establishments } from '~/repositories/establishmentRepository';
export const SirenStrasbourg = '246700488';
export const SirenSaintLo = '200066389';

export const ZeroLogementVacantEstablishment =
'Zéro Logement Vacant à Marseille';

export async function seed(knex: Knex): Promise<void> {
await Establishments(knex)
.whereIn('siren', [SirenStrasbourg, SirenSaintLo])
.update({ available: true });

// End-to-end test establishment
await Establishments(knex)
.where({ name: 'Zéro Logement Vacant à Marseille' })
.where({ name: ZeroLogementVacantEstablishment })
.delete();
await Establishments(knex).insert({
id: faker.string.uuid(),
name: 'Zéro Logement Vacant à Marseille',
name: ZeroLogementVacantEstablishment,
siren: Number(faker.string.numeric(9)),
available: true,
localities_geo_code: ['13055'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ import bcrypt from 'bcryptjs';
import { Knex } from 'knex';
import { v4 as uuidv4 } from 'uuid';

import { SirenSaintLo, SirenStrasbourg } from './20240404235442_establishments';
import {
SirenSaintLo,
SirenStrasbourg,
ZeroLogementVacantEstablishment
} from './20240404235442_establishments';
import { SALT_LENGTH, UserApi, UserRoles } from '~/models/UserApi';
import { Establishments } from '~/repositories/establishmentRepository';
import { formatUserApi, Users } from '~/repositories/userRepository';
Expand All @@ -14,12 +18,13 @@ import config from '~/infra/config';
export async function seed(knex: Knex): Promise<void> {
await Users(knex).delete();

const [strasbourg, saintLo] = await Promise.all([
const [strasbourg, saintLo, zlv] = await Promise.all([
Establishments(knex).where('siren', SirenStrasbourg).first(),
Establishments(knex).where('siren', SirenSaintLo).first()
Establishments(knex).where('siren', SirenSaintLo).first(),
Establishments(knex).where('name', ZeroLogementVacantEstablishment).first()
]);

if (!strasbourg || !saintLo) {
if (!strasbourg || !saintLo || !zlv) {
throw new Error('Establishments not found');
}

Expand Down Expand Up @@ -83,6 +88,7 @@ export async function seed(knex: Knex): Promise<void> {
password: await bcrypt.hash(config.e2e.password, SALT_LENGTH),
firstName: 'End',
lastName: 'TO END',
establishmentId: zlv.id,
role: UserRoles.Usual,
activatedAt: new Date(),
updatedAt: new Date()
Expand Down

0 comments on commit 0c7a012

Please sign in to comment.