Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions packages/datasource-firebase/src/collection.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import {
AggregateResult,
BaseCollection,
RecordData,
TSchema,
} from '@forestadmin/datasource-toolkit';

export default class FirebaseCollection extends BaseCollection {
async create(): Promise<RecordData[]> {
throw new Error('Method not implemented.');
}

async list(): Promise<RecordData[]> {
throw new Error('Method not implemented.');
}

async update(): Promise<void> {
throw new Error('Method not implemented.');
}

async delete(): Promise<void> {
throw new Error('Method not implemented.');
}

async aggregate(): Promise<AggregateResult<TSchema, string>[]> {
throw new Error('Method not implemented.');
}
}
8 changes: 8 additions & 0 deletions packages/datasource-firebase/src/datasource.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { BaseDataSource, Logger } from '@forestadmin/datasource-toolkit';
import FirebaseCollection from './collection';

export default class FirebaseDatasource extends BaseDataSource<FirebaseCollection> {
constructor(private readonly logger?: Logger) {
super();
}
}
10 changes: 10 additions & 0 deletions packages/datasource-firebase/src/index.ts
Original file line number Diff line number Diff line change
@@ -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);
}
54 changes: 54 additions & 0 deletions packages/datasource-firebase/test/collection.test.ts
Original file line number Diff line number Diff line change
@@ -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.'));
});
});
});
16 changes: 16 additions & 0 deletions packages/datasource-firebase/test/datasource.test.ts
Original file line number Diff line number Diff line change
@@ -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);
});
});
19 changes: 16 additions & 3 deletions packages/datasource-firebase/test/index.test.ts
Original file line number Diff line number Diff line change
@@ -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();
});
});
});