-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #49 from 21CSM/firebase-segregation
Firebase segregation
- Loading branch information
Showing
12 changed files
with
116 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { describe, it, expect, vi, beforeEach } from 'vitest'; | ||
|
||
const mockInitializeApp = vi.fn(() => ({ name: 'mocked-app' })); | ||
|
||
vi.mock('./config', () => ({ | ||
firebaseConfig: { | ||
apiKey: 'mock-api-key', | ||
authDomain: 'mock-auth-domain', | ||
projectId: "mock-project-id", | ||
storageBucket: "mock-storage-bucket", | ||
messagingSenderId: "mock-messaging-sender-id", | ||
appId: "mock-app-id", | ||
measurementId: "mock-measurement-id" | ||
} | ||
})); | ||
|
||
vi.mock('firebase/app', () => ({ | ||
initializeApp: mockInitializeApp | ||
})); | ||
|
||
describe('Firebase app initialization', () => { | ||
beforeEach(() => { | ||
vi.clearAllMocks(); | ||
}); | ||
it('initializes Firebase with the correct config', async () => { | ||
const { app } = await import('./app'); | ||
expect(mockInitializeApp).toHaveBeenCalledTimes(1); | ||
expect(mockInitializeApp).toHaveBeenCalledWith(expect.objectContaining({ | ||
apiKey: 'mock-api-key', | ||
authDomain: 'mock-auth-domain', | ||
projectId: "mock-project-id", | ||
storageBucket: "mock-storage-bucket", | ||
messagingSenderId: "mock-messaging-sender-id", | ||
appId: "mock-app-id", | ||
measurementId: "mock-measurement-id" | ||
})); | ||
expect(app).toEqual({ name: 'mocked-app' }); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import { initializeApp } from 'firebase/app'; | ||
import { firebaseConfig } from './config'; | ||
|
||
export const app = initializeApp(firebaseConfig); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { describe, it, expect, vi } from 'vitest'; | ||
import { getAuth } from 'firebase/auth'; | ||
|
||
vi.mock('firebase/auth', () => ({ | ||
getAuth: vi.fn(() => ({})), | ||
})); | ||
|
||
describe('Firebase Auth Initialization', () => { | ||
it('should call getAuth and initialize auth', async () => { | ||
const { auth } = await import('./auth'); | ||
expect(getAuth).toHaveBeenCalled(); | ||
expect(auth).toBeDefined(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import { getAuth } from "firebase/auth"; | ||
|
||
export const auth = getAuth(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,28 @@ | ||
import { describe, it, expect, vi } from 'vitest'; | ||
|
||
// Mock Firebase initialization | ||
vi.mock('firebase/app', () => { | ||
const mockApp = {}; | ||
return { | ||
initializeApp: vi.fn(() => mockApp) | ||
}; | ||
}); | ||
|
||
// Import after mocking | ||
import { initializeApp } from 'firebase/app'; | ||
import { app } from './config'; | ||
import { describe, it, expect } from 'vitest'; | ||
import { firebaseConfig } from './config'; | ||
|
||
describe('Firebase Configuration', () => { | ||
it('initializes Firebase with all required fields', () => { | ||
expect(initializeApp).toHaveBeenCalledWith( | ||
it('has all required fields', () => { | ||
expect(firebaseConfig).toEqual( | ||
expect.objectContaining({ | ||
apiKey: expect.any(String), | ||
authDomain: expect.any(String), | ||
projectId: expect.any(String), | ||
storageBucket: expect.any(String), | ||
messagingSenderId: expect.any(String), | ||
appId: expect.any(String) | ||
// Remove measurementId if it's not in your config | ||
appId: expect.any(String), | ||
measurementId: expect.any(String) | ||
}) | ||
); | ||
}); | ||
|
||
it('exports the initialized app', () => { | ||
expect(app).toBeDefined(); | ||
expect(app).toBe(vi.mocked(initializeApp).mock.results[0].value); | ||
it('has valid configuration values', () => { | ||
expect(firebaseConfig.apiKey).toMatch(/^AIza[0-9A-Za-z-_]{35}$/); | ||
expect(firebaseConfig.authDomain).toBe('ars-antiqua.firebaseapp.com'); | ||
expect(firebaseConfig.projectId).toBe('ars-antiqua'); | ||
expect(firebaseConfig.storageBucket).toBe('ars-antiqua.appspot.com'); | ||
expect(firebaseConfig.messagingSenderId).toMatch(/^\d+$/); | ||
expect(firebaseConfig.appId).toMatch(/^1:\d+:web:[a-f0-9]+$/); | ||
expect(firebaseConfig.measurementId).toMatch(/^G-[A-Z0-9]+$/); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,9 @@ | ||
import { initializeApp } from "firebase/app"; | ||
|
||
const firebaseConfig = { | ||
export const firebaseConfig = { | ||
apiKey: "AIzaSyBLIu54l_MFzG4G7QO34tUl6LhHUzfsEx4", | ||
authDomain: "ars-antiqua.firebaseapp.com", | ||
projectId: "ars-antiqua", | ||
storageBucket: "ars-antiqua.appspot.com", | ||
messagingSenderId: "42107927354", | ||
appId: "1:42107927354:web:4ce8583ae1a6cb8539ae03", | ||
measurementId: "G-9L07RXZCZD" | ||
}; | ||
|
||
export const app = initializeApp(firebaseConfig); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { describe, it, expect, vi } from 'vitest'; | ||
import { getFirestore } from 'firebase/firestore'; | ||
|
||
vi.mock('firebase/firestore', () => ({ | ||
getFirestore: vi.fn(() => ({})), | ||
})); | ||
|
||
describe('Firestore DB Initialization', () => { | ||
it('should call getFirestore and initialize db', async () => { | ||
const { db } = await import('./db'); | ||
expect(getFirestore).toHaveBeenCalled(); | ||
expect(db).toBeDefined(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import { getFirestore } from "firebase/firestore"; | ||
|
||
export const db = getFirestore(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { app } from './app'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { describe, it, expect, vi } from 'vitest'; | ||
import { getStorage } from 'firebase/storage'; | ||
|
||
vi.mock('firebase/storage', () => ({ | ||
getStorage: vi.fn(() => ({})), | ||
})); | ||
|
||
describe('Firebase Storage Initialization', () => { | ||
it('should call getStorage and initialize storage', async () => { | ||
const { storage } = await import('./storage'); | ||
expect(getStorage).toHaveBeenCalled(); | ||
expect(storage).toBeDefined(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import { getStorage } from "firebase/storage"; | ||
|
||
export const storage = getStorage(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,5 @@ | ||
export * from './firebase/config'; | ||
export * from './firebase/app'; | ||
export * from './firebase/auth'; | ||
export * from './firebase/config'; | ||
export * from './firebase/db'; | ||
export * from './firebase/storage'; |