diff --git a/packages/datasource-firebase/src/collection.ts b/packages/datasource-firebase/src/collection.ts new file mode 100644 index 0000000000..563190f9f9 --- /dev/null +++ b/packages/datasource-firebase/src/collection.ts @@ -0,0 +1,28 @@ +import { + AggregateResult, + BaseCollection, + RecordData, + TSchema, +} from '@forestadmin/datasource-toolkit'; + +export default class FirebaseCollection extends BaseCollection { + async create(): Promise { + throw new Error('Method not implemented.'); + } + + async list(): Promise { + throw new Error('Method not implemented.'); + } + + async update(): Promise { + throw new Error('Method not implemented.'); + } + + async delete(): Promise { + throw new Error('Method not implemented.'); + } + + async aggregate(): Promise[]> { + throw new Error('Method not implemented.'); + } +} diff --git a/packages/datasource-firebase/src/datasource.ts b/packages/datasource-firebase/src/datasource.ts new file mode 100644 index 0000000000..10f6f4e67c --- /dev/null +++ b/packages/datasource-firebase/src/datasource.ts @@ -0,0 +1,8 @@ +import { BaseDataSource, Logger } from '@forestadmin/datasource-toolkit'; +import FirebaseCollection from './collection'; + +export default class FirebaseDatasource extends BaseDataSource { + constructor(private readonly logger?: Logger) { + super(); + } +} diff --git a/packages/datasource-firebase/src/index.ts b/packages/datasource-firebase/src/index.ts index e69de29bb2..ba7a0ed6f6 100644 --- a/packages/datasource-firebase/src/index.ts +++ b/packages/datasource-firebase/src/index.ts @@ -0,0 +1,10 @@ +import { DataSourceFactory, Logger } from '@forestadmin/datasource-toolkit'; + +import FirebaseDataSource from './datasource'; + +export { default as FirebaseCollection } from './collection'; +export { default as FirebaseDataSource } from './datasource'; + +export function createFirebaseDataSource(): DataSourceFactory { + return async (logger: Logger) => new FirebaseDataSource(logger); +} diff --git a/packages/datasource-firebase/test/collection.test.ts b/packages/datasource-firebase/test/collection.test.ts new file mode 100644 index 0000000000..0a9304d9dc --- /dev/null +++ b/packages/datasource-firebase/test/collection.test.ts @@ -0,0 +1,54 @@ +import { FirebaseCollection, FirebaseDataSource } from '../src'; + +describe('FirebaseCollection', () => { + it('should allow to create a collection', () => { + const datasource = {} as unknown as FirebaseDataSource; + const collection = new FirebaseCollection('test', datasource); + expect(collection).toBeInstanceOf(FirebaseCollection); + }); + + describe('create', () => { + it('should throw an error', async () => { + const datasource = {} as unknown as FirebaseDataSource; + const collection = new FirebaseCollection('test', datasource); + + await expect(collection.create()).rejects.toEqual(new Error('Method not implemented.')); + }); + }); + + describe('list', () => { + it('should throw an error', async () => { + const datasource = {} as unknown as FirebaseDataSource; + const collection = new FirebaseCollection('test', datasource); + + await expect(collection.list()).rejects.toEqual(new Error('Method not implemented.')); + }); + }); + + describe('update', () => { + it('should throw an error', async () => { + const datasource = {} as unknown as FirebaseDataSource; + const collection = new FirebaseCollection('test', datasource); + + await expect(collection.update()).rejects.toEqual(new Error('Method not implemented.')); + }); + }); + + describe('delete', () => { + it('should throw an error', async () => { + const datasource = {} as unknown as FirebaseDataSource; + const collection = new FirebaseCollection('test', datasource); + + await expect(collection.delete()).rejects.toEqual(new Error('Method not implemented.')); + }); + }); + + describe('aggregate', () => { + it('should throw an error', async () => { + const datasource = {} as unknown as FirebaseDataSource; + const collection = new FirebaseCollection('test', datasource); + + await expect(collection.aggregate()).rejects.toEqual(new Error('Method not implemented.')); + }); + }); +}); diff --git a/packages/datasource-firebase/test/datasource.test.ts b/packages/datasource-firebase/test/datasource.test.ts new file mode 100644 index 0000000000..e9093880c5 --- /dev/null +++ b/packages/datasource-firebase/test/datasource.test.ts @@ -0,0 +1,16 @@ +import { Logger } from '@forestadmin/datasource-toolkit'; + +import { FirebaseDataSource } from '../src'; + +describe('FirebaseDataSource', () => { + it('should create a new datasource without a logger', () => { + const datasource = new FirebaseDataSource(); + expect(datasource).toBeInstanceOf(FirebaseDataSource); + }); + + it('should create a new datasource with a logger', () => { + const logger = {}; + const datasource = new FirebaseDataSource(logger as unknown as Logger); + expect(datasource).toBeInstanceOf(FirebaseDataSource); + }); +}); diff --git a/packages/datasource-firebase/test/index.test.ts b/packages/datasource-firebase/test/index.test.ts index 9875f2acbd..ddd8cc5a66 100644 --- a/packages/datasource-firebase/test/index.test.ts +++ b/packages/datasource-firebase/test/index.test.ts @@ -1,5 +1,18 @@ -describe('firebase > index', () => { - it('should build (fake test to be able to create the package)', () => { - expect(true).toBeTruthy(); +import { FirebaseCollection, FirebaseDataSource, createFirebaseDataSource } from '../src/index'; + +describe('exports', () => { + describe('createFirebaseDataSource', () => { + it('should export a factory function', () => { + expect(createFirebaseDataSource).toBeInstanceOf(Function); + }); + }); + + describe.each([ + ['FirebaseCollection', FirebaseCollection], + ['FirebaseDataSource', FirebaseDataSource], + ])('class %s', (message, type) => { + it('should be defined', () => { + expect(type).toBeDefined(); + }); }); });