agentleFS
LeanMeanCleanAppsLeanMeanCleanApps/CleanGraphQLApi/.agents/skills/presentation-integration-tests/SKILL.md

presentation-integration-tests

Skill13 starsChanged 10 days agoMITView on GitHub

How this GraphQL API is tested end to end with WebApplicationFactory - the GraphQLApplication host, one app and database per test class, sending queries and mutations over HTTP, reading data and errors with typed test models, the schema snapshot, and testing with authentication on. Use when writing or fixing a test in tests/Presentation.Tests.Integration.

4 other projects use a version of this, 3 of them edited.

Adopted by

Most recently taken up by

The file

We split this skill into the rules it gives an agent

1 rule. 0 are common, 0 are distinctive, and 1 is very specific to this project.

  • 0

    Common

    Most of the 4 edited versions we read keep these.

  • 0

    Distinctive

    This author's own choices. Worth a look.

  • 1

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    Put the test in GraphQL/<Feature>/<Feature>Tests.cs with private readonly GraphQLApplication application = new().

    line 23

“Common” is measured: kept by at least 6 in 10 of the 4 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Presentation integration tests (GraphQL)

The rule

The GraphQL layer is tested through HTTP in tests/Presentation.Tests.Integration. ApplicationErrorFilter, PageExtensions and, with authentication, AuthenticationSettings are also tested on their own in tests/Presentation.Tests.Unit (unit-tests). GraphQLApplication (a WebApplicationFactory<Program>) starts the app with the local environment, its own shared-cache in-memory SQLite database and the sample data on. Each test class creates one in a field, implements IDisposable and disposes it, so no class shares data with another.

PieceWhereUse it to
GraphQLApplication(environment, settings, configureServices)GraphQLApplication.csStart the app, with other settings or services when needed
Deserialize<T>(), ToStringContent()Serializer.csRead a response into a test model, and send a query with variables as JSON
GraphData, Data, Error, Connection<T>GraphQL/Common/The shape of a GraphQL response: data and errors
Per-feature modelsGraphQL/<Feature>/The fields a test asks for

Steps

  1. Put the test in GraphQL/<Feature>/<Feature>Tests.cs with private readonly GraphQLApplication application = new(); and the Dispose pattern from the other classes.
  2. Queries can go in the URL (/graphql?query={...}). Mutations and anything with variables are POSTed as { query, variables } with ToStringContent().
  3. A GraphQL response is 200 OK even when it has errors. Assert the status, then errors or data.
  4. For failures, assert errors[0].extensions.code (VALIDATION, NOT_FOUND) and the messages (api-conventions).
  5. Find rows through the API (list, then pick one), not by hard-coded ids.
  6. A schema change also updates the snapshot (schema-snapshot).
  7. In a solution with authentication, its tests pass Authentication:* settings and a test signing key. See Authentication/AuthenticationTests.cs.

Example

// tests/Presentation.Tests.Integration/GraphQL/Movies/MovieTests.cs
public class MovieTests : IDisposable
{
    private readonly GraphQLApplication application = new();

    [Fact]
    public async Task Movies_ShouldReturn_MoviesList()
    {
        // Arrange
        using var client = this.application.CreateClient();

        // Act
        using var response = await client.GetAsync("/graphql?query={movies(first:50){nodes{id,title,reviewCount,averageStars,reviews{id,stars,author{id,firstName,lastName}}}}}");
        var result = (await response.Content.ReadAsStringAsync()).Deserialize<GraphData>();

        // Assert
        response.StatusCode.ShouldBe(HttpStatusCode.OK);
        result.Data.Movies.Nodes.Length.ShouldBe(50);
    }
}

Don't

  • Share an application across tests with a static field or a class fixture.
  • Assert only the status code. It's 200 for errors too.
  • Edit appsettings files for a test. Pass settings.
  • Depend on order the query doesn't promise.

Check

dotnet test tests/Presentation.Tests.Integration

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.