0


我正在尝试测试一个只有创建事件的用户才能修改它的突变。我按照nexus教程设置测试环境,测试如下:

it("ensures that only the host can modify an event", async () => {
  await createTestUser(ctx, "Test", "User", "test@test.com", "mySecretPassword")
  const event = await createTestEvent(ctx, event_data.title, event_data.description, when, address)
  ctx.client.setHeader("authorization", "")
  await createTestUser(ctx, "Test2", "User2", "test@test2.com", "mySecretPassword2")
  async function modifyEvent() {
    const modified_event_response = await ctx.client.request(gql`
      mutation updateDescription($event_id: String!) {
        updateDescription(event_id: $event_id, description: "This is the updated description.") {
          event_id
          description
        }
      }
    `,{ event_id: event.event_id }
    );
    return modified_event_response
  }
  expect(modifyEvent()).toThrow("Sorry, but you are not allowed to do this")
})

但是当我尝试运行这个测试时,我得到了这个错误:

FetchError: request to http://localhost:4000/ failed, reason: connect ECONNREFUSED 127.0.0.1:4000

我不能在函数中运行突变吗?

4

0 回答 0