Skip to content

Unit Tests? "Missing values for: hostName" #1116

@ceri-waterscreative

Description

@ceri-waterscreative

Hiya,

I wish to write Unit tests for a few of my functions which require the admin object.

I've tried using unathenticated requests for this, but alas I keep getting an error..
ShopifyError: Cannot initialize Shopify API Library. Missing values for: hostName

I can confirm I'm passing in my environment file too, and the required environment variables are there.

My code if that helps..

import prisma from '../db.server.js';
import { PrismaSessionStorage } from '@shopify/shopify-app-session-storage-prisma';
import { setUpValidSession } from '@shopify/shopify-api/test-helpers';
import { test as testOrderPaid } from './order-paid.server.js';
import {
  ApiVersion,
  AppDistribution,
  shopifyApp,
} from "@shopify/shopify-app-remix/server";
import { testShopifyStore } from './helpers.server.js';

const sessionStorage = new PrismaSessionStorage(prisma);
const session = setUpValidSession({
    shop: testShopifyStore,
});
await sessionStorage.storeSession(session);

const shopify = shopifyApp({
  apiKey: process.env.SHOPIFY_API_KEY,
  apiSecretKey: process.env.SHOPIFY_API_SECRET || "",
  apiVersion: ApiVersion.January25,
  scopes: process.env.SCOPES?.split(","),
  appUrl: process.env.SHOPIFY_APP_URL || "",
  hostName: process.env.SHOPIFY_APP_URL || "",
  authPathPrefix: "/auth",
  sessionStorage: sessionStorage,
  distribution: AppDistribution.AppStore,
  future: {
    unstable_newEmbeddedAuthStrategy: true,
    removeRest: true,
  },
  ...(process.env.SHOP_CUSTOM_DOMAIN
    ? { customShopDomains: [process.env.SHOP_CUSTOM_DOMAIN] }
    : {}),
});

const { unauthenticated } = shopify;

// Testing..

const { admin } = await unauthenticated(testShopifyStore);

const response = await testOrderPaid(admin, session);
if(response.result === false){
    throw new Error("Order Paid Test Failed: " + JSON.stringify(response.errors));
} else {
    console.log("Order Paid Test Passed");
}

Any ideas??

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions