Skip to content

Commit

Permalink
move unit tests to integration tests instead
Browse files Browse the repository at this point in the history
  • Loading branch information
zth committed May 2, 2024
1 parent d0acb5c commit a535f18
Show file tree
Hide file tree
Showing 4 changed files with 199 additions and 329 deletions.
252 changes: 0 additions & 252 deletions packages/cli/src/__snapshots__/rescript.test.ts.snap

This file was deleted.

65 changes: 2 additions & 63 deletions packages/cli/src/rescript.test.ts
Original file line number Diff line number Diff line change
@@ -1,64 +1,3 @@
import { parseCode } from './parseRescript.js';

test('parser finds string template in correct file', () => {
const fileContent = `
let query = %sql.one(\`
/* @name FindBookById */
SELECT * FROM books WHERE id = :id;
\`);
`;

const result = parseCode(fileContent);
expect(result).toMatchSnapshot();
});

test('inserts trailing semicolon when needed', () => {
const fileContent = `
let query = %sql.one(\`
/* @name FindBookById */
SELECT * FROM books WHERE id = :id
\`);
let queryMany = %sql.many(\`
/* @name FindBooks */
SELECT * FROM books
\`);
`;

const result = parseCode(fileContent);
expect(result).toMatchSnapshot();
});

test('inserts @name when needed', () => {
const fileContent = `
let query = %sql.one(\`
/* @name FindBookById */
SELECT * FROM books WHERE id = :id
\`);
let queryMany = %sql.many(\`
SELECT * FROM books
\`);
let queryExpect = %sql.expectOne(\`
SELECT * FROM books WHERE id = :id
\`);
`;

const result = parseCode(fileContent);
expect(result).toMatchSnapshot();
});

test('preserves @param when inserting @name', () => {
const fileContent = `
let query = %sql.one(\`
/*
@param notification -> (payload, user_id, type)
*/
INSERT INTO notifications (payload, user_id, type) VALUES :notification
\`);
`;

const result = parseCode(fileContent);
expect(result).toMatchSnapshot();
test('test', () => {
expect(true).toBe(true);
});
12 changes: 12 additions & 0 deletions packages/example/src/books/BookService.res
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,15 @@ let booksByAuthor = (client, ~authorName) => {

client->query({authorName: authorName})
}

let queryWithParams = %sql.one(`
/*
@param notification -> (payload, user_id, type)
*/
INSERT INTO notifications (payload, user_id, type) VALUES :notification
`)

let queryWithParamsSingleLine = %sql.one(`
/* @param notification -> (payload, user_id, type) */
INSERT INTO notifications (payload, user_id, type) VALUES :notification
`)
Loading

0 comments on commit a535f18

Please sign in to comment.