This repository has been archived on 2026-11-17. You can view files and clone it, but cannot push or open issues or pull requests.
gitgram-ai/gitgram/backend/tests/e2e/snippets.e2e.test.ts
caelum0x 64fbe9f474 feat: round-3 deep product build-out (69 gaps closed, all 7 products green)
Deep-audit + build-out across all products to fully-usable state; all typecheck clean.

- gitgram-web (99): wire Store feature to real endpoints, close 9 gaps
- gitgram-backend (100): close 8 flow gaps, document infra-provisioning items
- gitgram-mobile (90): fix API base-URL/path mismatch (404s) + copy proximity
  components into components/proximity wired to real screens; 15 gaps, +react-native-svg
- aitm-core (95): wire natural-language CLI flow end-to-end; 11 gaps
- aitm-api (97): fix teams metadata runtime bug; copy a2a-js server/client/grpc
  into src/a2a and wire A2A route; crates.io package search; 8 gaps
- aitm-mcp (100): fix A2A client/server card mismatch; 9 gaps
- aitm-website (95): build missing docs routes; 9 gaps

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-28 13:54:57 +03:00

100 lines
3.2 KiB
TypeScript

/**
* E2E: Code snippets social parity.
*
* Verifies the snippet CRUD plus the newly-added comments and likers endpoints
* (social parity with posts) end-to-end against a live database.
*/
import request from 'supertest';
import type { Express } from 'express';
import { buildApp, registerUser, bearer, resetDatabase, RegisteredUser } from './helpers';
describe('E2E: Snippets social parity', () => {
let app: Express;
let owner: RegisteredUser;
let other: RegisteredUser;
let snippetId: string;
beforeAll(async () => {
app = buildApp();
await resetDatabase();
owner = await registerUser(app);
other = await registerUser(app);
});
it('creates a snippet', async () => {
const res = await request(app)
.post('/api/v1/snippets')
.set(...bearer(owner.token))
.send({
title: 'Hello',
code: 'console.log("hi")',
language: 'javascript',
description: 'a greeting',
});
expect(res.status).toBe(201);
expect(res.body.id).toBeTruthy();
snippetId = res.body.id;
});
it('toggles like / unlike and lists likers', async () => {
const like = await request(app)
.post(`/api/v1/snippets/${snippetId}/like`)
.set(...bearer(other.token));
expect(like.status).toBe(200);
expect(like.body.liked).toBe(true);
const likers = await request(app)
.get(`/api/v1/snippets/${snippetId}/likers`)
.set(...bearer(owner.token));
expect(likers.status).toBe(200);
expect(Array.isArray(likers.body.likers)).toBe(true);
expect(likers.body.likers.some((u: { id: string }) => u.id === other.id)).toBe(true);
expect(likers.body.total).toBeGreaterThanOrEqual(1);
const unlike = await request(app)
.post(`/api/v1/snippets/${snippetId}/like`)
.set(...bearer(other.token));
expect(unlike.body.liked).toBe(false);
});
it('adds and lists comments (with replies)', async () => {
const comment = await request(app)
.post(`/api/v1/snippets/${snippetId}/comments`)
.set(...bearer(other.token))
.send({ content: 'Nice snippet!' });
expect(comment.status).toBe(201);
expect(comment.body.content).toBe('Nice snippet!');
const parentId = comment.body.id;
const reply = await request(app)
.post(`/api/v1/snippets/${snippetId}/comments`)
.set(...bearer(owner.token))
.send({ content: 'Thanks!', parentId });
expect(reply.status).toBe(201);
const list = await request(app)
.get(`/api/v1/snippets/${snippetId}/comments`)
.set(...bearer(owner.token));
expect(list.status).toBe(200);
expect(list.body.total).toBeGreaterThanOrEqual(1);
expect(list.body.comments[0]._count.replies).toBeGreaterThanOrEqual(1);
});
it('rejects an empty comment at the validation boundary', async () => {
const res = await request(app)
.post(`/api/v1/snippets/${snippetId}/comments`)
.set(...bearer(other.token))
.send({ content: '' });
expect(res.status).toBe(400);
});
it('returns 404 when commenting on a missing snippet', async () => {
const res = await request(app)
.post('/api/v1/snippets/missing-snippet/comments')
.set(...bearer(other.token))
.send({ content: 'hi' });
expect(res.status).toBe(404);
});
});