ticketSetUp static method
avoid adding boutique_service depency in ticket_service just to get unit test rolling also a lot of half-mocked logic to recreate objects prod like since we delegate id management to mongodb, we need to create firm, then chain, then boutique and pass their ids to the counterfoil used by the ticket
Implementation
static Future<Counterfoil> ticketSetUp(Db db, Connection connection) async {
await db.open();
await connection.connect();
var fenceService = FenceService(
db,
isMock: true,
userPermissionIfTest: Dummy.adminPermission,
);
await db.createCollection(fenceService.userCollection.collectionName);
await db.createCollection(fenceService.boutiqueCollection.collectionName);
final responseUser = await fenceService.createPendingUser(
null,
PendingUserRequest(
mail: Dummy.userInfo.mail,
firstname: Dummy.userInfo.firstname,
lastname: Dummy.userInfo.lastname,
permissions: Dummy.userInfo.permissions,
phone: Dummy.userInfo.phone,
),
);
final response = await fenceService.createFirm(null, CreateFirmRequest());
final firm = await fenceService.readOneFirm(null, Empty());
final chainsResponse = await fenceService.readAllChains(null, Empty());
fenceService..userPermissionIfTest = Dummy.adminPermission;
return Counterfoil.create()
..firmId = response.firm.firmId
..chainId = chainsResponse.chains.first.chainId
..boutiqueId = chainsResponse.chains.first.boutiques.first.boutiqueId
..userId = Dummy.userInfo.userId;
}