Skip to content

Commit

Permalink
refactor: renames func
Browse files Browse the repository at this point in the history
  • Loading branch information
jlong4223 committed Nov 21, 2024
1 parent 6bba618 commit b024481
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
9 changes: 6 additions & 3 deletions src/__tests__/faunav10.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { describe, test, expect, beforeEach } from 'vitest';
import { faunaClientV10, setFaunaSecretV10 } from '../v10/setFaunaSecret';
import { getRawCollectionData } from '../v10/getRawCollectionData';
import { getRawDataById } from '../v10/getRawDataById';
import { getRawDocDataById } from '../v10/getRawDocDataById';
import { Client } from 'fauna';

const faunaSecret = import.meta.env.VITE_V10_FAUNA_SECRET;
Expand Down Expand Up @@ -44,14 +44,17 @@ describe('all functions tests', () => {
test('should return a single document by id', async () => {
const productId = '378217320570421325';

const singleProduct = await getRawDataById('Product', productId);
const singleProduct = await getRawDocDataById('Product', productId);

expect(singleProduct.data.id).toEqual(productId);
expect(singleProduct.data.name).toEqual('avocados');
});
test('should error with an invalid id', async () => {
const invalidId = '378217320570421324';
const singleProductResponse = await getRawDataById('Product', invalidId);
const singleProductResponse = await getRawDocDataById(
'Product',
invalidId
);

expect(singleProductResponse).toMatchObject({
data: { cause: 'not found' }
Expand Down
10 changes: 7 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@ import { getRawCollectionData } from './v10/getRawCollectionData';
import {
RawCollectionData,
RawDocument,
PaginatedDocuments
PaginatedDocuments,
RawDocumentById
} from './types/v10';
import { getRawDocDataById } from './v10/getRawDocDataById';

export {
faunaClient,
Expand All @@ -39,7 +41,8 @@ export {
/* v10 below */
faunaClientV10,
setFaunaSecretV10,
getRawCollectionData
getRawCollectionData,
getRawDocDataById
};

export type {
Expand All @@ -52,5 +55,6 @@ export type {
/* v10 below */
RawCollectionData,
RawDocument,
PaginatedDocuments
PaginatedDocuments,
RawDocumentById
};
2 changes: 1 addition & 1 deletion src/v10/getRawDataById.ts → src/v10/getRawDocDataById.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { fql } from 'fauna';
import { faunaClientV10 } from './setFaunaSecret';
import { RawDocumentById } from '../types/v10';

export const getRawDataById = async (collectionName: string, id: string) => {
export const getRawDocDataById = async (collectionName: string, id: string) => {
const getCollectionDocById = fql`Collection(${collectionName}).byId(${id})`;
const documentById: RawDocumentById =
await faunaClientV10.query(getCollectionDocById);
Expand Down

0 comments on commit b024481

Please sign in to comment.