0

I'm trying to test an auth endpoint in strapi, And in my strapi app I'm running migrations but everytime I run the migrations with this line await strapi.plugin('migrations').service('migrations').migrations();

It always fail with this error error Command failed with signal "SIGSEGV".

And the migrations don't run.enter image description here

I did try to add plugins.ts inside my test env with this configuration

export default ({ env }) => ({
  'migrations': {
    enabled: true,
    config: {
      autoStart: false,
      migrationFolderPath: 'migrations',
    },
  },
}

And still while running my testcases along with the migrations to create an auth user I got this error error Command failed with signal "SIGSEGV".

NOTE: I need to run the migrations to be able to have find user-permissions.

And here is the code to create an auth user ->

export async function createUserWithAuthenticatedRole() {

const mockUserData = {
    username: 'test',
    email: 'test@test.local',
    provider: 'local',
    password: 'test',
    confirmed: true,
    blocked: null,
    role: null
  };

  const advanced = await strapi.store({
    type: 'plugin',
    name: 'users-permissions',
    key: 'advanced'
  }).get();

  const defaultRole = await strapi.query('users-permissions.role').findOne({
    type: advanced.default_role
  });

  mockUserData.role = defaultRole.id; // Assign the Authenticated role to the user

  const userService = strapi.plugin('users-permissions').services.user;

  const user = await userService.create({
    ...mockUserData
  });

  return user;
};
beforeAll(async () => {
  await setupStrapi();

  await strapi.plugin('migrations').service('migrations').migrations();

  server = strapi.server.app.callback();

  let user = await createUserWithAuthenticatedRole();
  console.log(user);

  const response = await request(server)
  .post('/auth/local')
  .send({
    identifier: 'test@test.local',
    password: 'test',
  });

  console.log(response.body)

  authToken = response.body.jwt;
  console.log(authToken)
});

I'm using strapi 4.10.1 and for testing I'm using jest and have been following strapi documentation: https://docs.strapi.io/dev-docs/testing#test-an-auth-endpoint-controller

0 Answers0