Skip to content

Commit

Permalink
Updated tests
Browse files Browse the repository at this point in the history
  • Loading branch information
maneesht committed Sep 19, 2024
1 parent 00f86c0 commit da31e42
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 8 deletions.
2 changes: 1 addition & 1 deletion packages/data-connect/src/network/fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export function dcFetch<T, U>(
if (accessToken) {
headers['X-Firebase-Auth-Token'] = accessToken;
}
if(appId) {
if (appId) {
headers['x-firebase-gmpid'] = appId;
}
if (appCheckToken) {
Expand Down
20 changes: 18 additions & 2 deletions packages/data-connect/test/unit/fetch.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,15 @@ describe('fetch', () => {
message
});
await expect(
dcFetch('http://localhost', {}, {} as AbortController, null, null, null, false)
dcFetch(
'http://localhost',
{},
{} as AbortController,
null,
null,
null,
false
)
).to.eventually.be.rejectedWith(message);
});
it('should throw a stringified message when the server responds with an error without a message property in the body', async () => {
Expand All @@ -51,7 +59,15 @@ describe('fetch', () => {
};
mockFetch(json);
await expect(
dcFetch('http://localhost', {}, {} as AbortController, null, null, null, false)
dcFetch(
'http://localhost',
{},
{} as AbortController,
null,
null,
null,
false
)
).to.eventually.be.rejectedWith(JSON.stringify(json));
});
});
14 changes: 9 additions & 5 deletions packages/data-connect/test/unit/gmpid.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ const fakeFetchImpl = sinon.stub().returns(
describe('GMPID Tests', () => {
let dc: DataConnect;
let app: FirebaseApp;
let APPID = 'MYAPPID';
const APPID = 'MYAPPID';
beforeEach(() => {
initializeFetch(fakeFetchImpl);
app = initializeApp({ projectId: 'p',appId: APPID }, 'fdsasdf'); // TODO(mtewani): Replace with util function
app = initializeApp({ projectId: 'p', appId: APPID }, 'fdsasdf'); // TODO(mtewani): Replace with util function
dc = getDataConnect(app, { connector: 'c', location: 'l', service: 's' });
});
afterEach(async () => {
Expand All @@ -63,7 +63,11 @@ describe('GMPID Tests', () => {
});
it('should send a request with no gmpid if using the app id is not specified', async () => {
const app2 = initializeApp({ projectId: 'p' }, 'def'); // TODO(mtewani): Replace with util function
const dc2 = getDataConnect(app2, { connector: 'c', location: 'l', service: 's' });
const dc2 = getDataConnect(app2, {
connector: 'c',
location: 'l',
service: 's'
});
// @ts-ignore
await executeQuery(queryRef(dc2, '')).catch(() => {});
expect(fakeFetchImpl).to.be.calledWithMatch(
Expand All @@ -74,7 +78,7 @@ describe('GMPID Tests', () => {
}
}
);
dc2._delete();
deleteApp(app2);
await dc2._delete();
await deleteApp(app2);
});
});

0 comments on commit da31e42

Please sign in to comment.