#!/bin/bash

set -euo pipefail
export GO111MODULE=on
cd integration

date
go run ./server/cmd/integration/server.go &

sleep 5
curl -s --connect-timeout 5 \
    --max-time 10 \
    --retry 5 \
    --retry-delay 5 \
    --retry-max-time 40 \
    --retry-connrefused \
    localhost:8080 > /dev/null


echo "### validating introspected schema"
npm run gen

if ! diff <(tail -n +3 src/generated/schema-expected.graphql) <(tail -n +3 src/generated/schema-fetched.graphql) ; then
    echo "The expected schema has changed, you need to update schema-expected.graphql with any expected changes"
    exit 1
fi

echo "### running integration spec"
npm run test
