adonis-responsive-attachment
adonis-responsive-attachment copied to clipboard
Usage in factories?
I have a factory like so
import Factory from '@ioc:Adonis/Lucid/Factory';
import ServiceProviderProfile from 'App/Models/ServiceProviderProfile';
import { ResponsiveAttachment } from '@ioc:Adonis/Addons/ResponsiveAttachment';
import { readFile } from 'node:fs/promises';
import { join } from 'node:path';
export default Factory.define(ServiceProviderProfile, async ({ faker }) => {
const avatarImage = await ResponsiveAttachment.fromBuffer(
await readFile(join(__dirname, '../../tests/resources/default-avatar.png'))
);
await avatarImage.setOptions({
forceFormat: 'webp',
keepOriginal: true,
folder: 'avatars/service-provider',
breakpoints: {
xlarge: 1200,
large: 800,
medium: 300,
small: 100
}
});
await avatarImage.save();
return {
name: faker.name.findName(),
avatar: avatarImage, // this ends up as null
about: faker.random.words(100),
specialties: faker.random.words(5).split(' ').join(', ')
};
}).build();
The images are processed and saved to disk. avatarImage
is the correct object before the return. Is there something else I need to do to make this work in a factory?