InitialState now accepts optional refs, commits, issues, and
pullRequests arrays. They default to empty arrays, so existing fixtures do
not need to change.
import {type InitialState, simulation} from 'simulacat-core';
const initialState: InitialState = {
users: [],
organizations: [{login: 'acme'}],
repositories: [{owner: 'acme', name: 'awesome-repo'}],
branches: [{owner: 'acme', repo: 'awesome-repo', name: 'main'}],
blobs: [],
commits: [{owner: 'acme', repo: 'awesome-repo', sha: 'abc123'}],
refs: [
{
owner: 'acme',
repo: 'awesome-repo',
qualifiedName: 'main',
object: {sha: 'abc123'}
}
],
issues: [{owner: 'acme', repo: 'awesome-repo', number: 1, title: 'Bug'}],
pullRequests: [
{
owner: 'acme',
repo: 'awesome-repo',
number: 2,
title: 'Fix bug',
base: {ref: 'main', sha: 'abc123'},
head: {ref: 'feature/fix', sha: 'def456'}
}
]
};
const app = simulation({initialState});
const server = await app.listen(0);
try {
const baseUrl = `http://127.0.0.1:${server.port}`;
const paths = [
'/repos/acme/awesome-repo/git/ref/main',
'/repos/acme/awesome-repo/git/commits/abc123',
'/repos/acme/awesome-repo/issues/1',
'/repos/acme/awesome-repo/pulls/2'
];
const rest = await Promise.all(
paths.map(async (path) => {
const response = await fetch(`${baseUrl}${path}`);
return {status: response.status, body: await response.json()};
})
);
const query = `query {
repository(owner: "acme", name: "awesome-repo") {
defaultBranchRef { name }
ref(qualifiedName: "main") { name }
issues(first: 10) { nodes { number } }
pullRequests(first: 10) { nodes { number } }
}
}`;
const graphQlResponse = await fetch(`${baseUrl}/graphql`, {
method: 'POST',
headers: {'content-type': 'application/json'},
body: JSON.stringify({query})
});
const graphQl = await graphQlResponse.json();
console.log(JSON.stringify({rest, graphQl}));
} finally {
await server.ensureClose();
}
Seeded refs, commits, issues, and pull requests are visible through the
documented REST endpoints and through repository GraphQL fields such as
defaultBranchRef, ref, issues, and pullRequests.