console/integration-tests/tests/api/schema/schema-version.spec.ts
jdolle caebbe093a
fix: schema version by commit (#7155)
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
2025-10-24 10:54:47 +02:00

69 lines
1.7 KiB
TypeScript

import { ProjectType } from 'testkit/gql/graphql';
import { graphql } from '../../../testkit/gql';
import { execute } from '../../../testkit/graphql';
import { initSeed } from '../../../testkit/seed';
const SchemaByCommitQuery = graphql(/* GraphQL */ `
query SchemaByCommitQuery($commit: String!, $targetRef: TargetReferenceInput) {
schemaVersionByCommit(commit: $commit, target: $targetRef) {
id
sdl
log {
... on PushedSchemaLog {
id
commit
}
}
}
}
`);
test.concurrent(
'schema version by commit returns latest schema for the commit',
async ({ expect }) => {
const commit = 'tiny-test-0';
const schema = /* GraphQL */ `
type Query {
ping: String
}
`;
const latestSchema = /* GraphQL */ `
type Query {
ping: String
pong: String
}
`;
const { createOrg } = await initSeed().createOwner();
const { createProject } = await createOrg();
const { createTargetAccessToken, target } = await createProject(ProjectType.Single);
const token = await createTargetAccessToken({
mode: 'readWrite',
});
await token
.publishSchema({
sdl: schema,
commit,
})
.then(r => r.expectNoGraphQLErrors());
await token
.publishSchema({
sdl: latestSchema,
commit,
})
.then(r => r.expectNoGraphQLErrors());
const result = await execute({
document: SchemaByCommitQuery,
token: token.secret,
variables: {
commit,
targetRef: { byId: target.id },
},
}).then(r => r.expectNoGraphQLErrors());
expect(result.schemaVersionByCommit?.sdl).toIncludeSubstringWithoutWhitespace(latestSchema);
},
);