Skip to content

Commit 1932400

Browse files
committed
Fixed linting
1 parent a51822f commit 1932400

File tree

4 files changed

+106
-56
lines changed

4 files changed

+106
-56
lines changed

packages/data-connect/src/api/DataConnect.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,10 @@ export class DataConnect {
179179

180180
// @internal
181181
enableEmulator(transportOptions: TransportOptions): void {
182-
if (this._initialized && !areTransportOptionsEqual(this._transportOptions, transportOptions)) {
182+
if (
183+
this._initialized &&
184+
!areTransportOptionsEqual(this._transportOptions, transportOptions)
185+
) {
183186
logError('enableEmulator called after initialization');
184187
throw new DataConnectError(
185188
Code.ALREADY_INITIALIZED,
@@ -192,8 +195,13 @@ export class DataConnect {
192195
}
193196

194197
// @internal
195-
export function areTransportOptionsEqual(transportOptions1: TransportOptions, transportOptions2: TransportOptions) {
196-
return JSON.stringify(transportOptions1) === JSON.stringify(transportOptions2);
198+
export function areTransportOptionsEqual(
199+
transportOptions1: TransportOptions,
200+
transportOptions2: TransportOptions
201+
) {
202+
return (
203+
JSON.stringify(transportOptions1) === JSON.stringify(transportOptions2)
204+
);
197205
}
198206

199207
/**

packages/data-connect/src/api/query.ts

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -125,13 +125,27 @@ export function queryRef<Data, Variables>(
125125
initialCache?: QueryResult<Data, Variables>
126126
): QueryRef<Data, Variables> {
127127
dcInstance.setInitialized();
128-
if(typeof queryNameOrSerializedRef === 'string') {
129-
dcInstance._queryManager.track(queryNameOrSerializedRef, variables, initialCache);
128+
if (typeof queryNameOrSerializedRef === 'string') {
129+
dcInstance._queryManager.track(
130+
queryNameOrSerializedRef,
131+
variables,
132+
initialCache
133+
);
130134
} else {
131-
dcInstance._queryManager.track(queryNameOrSerializedRef.refInfo.name, queryNameOrSerializedRef.refInfo.variables, queryNameOrSerializedRef);
135+
dcInstance._queryManager.track(
136+
queryNameOrSerializedRef.refInfo.name,
137+
queryNameOrSerializedRef.refInfo.variables,
138+
queryNameOrSerializedRef
139+
);
132140
}
133-
const vars = typeof queryNameOrSerializedRef !== 'string'? queryNameOrSerializedRef.refInfo.variables : variables;
134-
const name = typeof queryNameOrSerializedRef !== 'string'? queryNameOrSerializedRef.refInfo.name : queryNameOrSerializedRef;
141+
const vars =
142+
typeof queryNameOrSerializedRef !== 'string'
143+
? queryNameOrSerializedRef.refInfo.variables
144+
: variables;
145+
const name =
146+
typeof queryNameOrSerializedRef !== 'string'
147+
? queryNameOrSerializedRef.refInfo.name
148+
: queryNameOrSerializedRef;
135149
return {
136150
dataConnect: dcInstance,
137151
refType: QUERY_STR,

packages/data-connect/test/queries.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,11 +138,11 @@ describe('DataConnect Tests', async () => {
138138
expect(result.data).to.eq(queryResult.data);
139139
expect(result.source).to.eq(SOURCE_CACHE);
140140
});
141-
141+
142142
it(`returns the result source as cache when data already exists`, async () => {
143143
const taskListQuery = queryRef<TaskListResponse>(dc, 'listPosts');
144144
const queryResult = await executeQuery(taskListQuery);
145-
const serializedRef = queryResult.toJSON();
145+
const serializedRef = queryResult.toJSON();
146146
const newRef = queryRef(dc, serializedRef);
147147
expect(newRef.name).to.eq(serializedRef.refInfo.name);
148148
expect(newRef.variables).to.eq(serializedRef.refInfo.variables);
Lines changed: 74 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,80 @@
1+
/**
2+
* @license
3+
* Copyright 2024 Google LLC
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
118
import { expect } from 'chai';
2-
import { TransportOptions, areTransportOptionsEqual, connectDataConnectEmulator, getDataConnect} from '../../src/api/DataConnect';
19+
import {
20+
TransportOptions,
21+
areTransportOptionsEqual,
22+
connectDataConnectEmulator,
23+
getDataConnect
24+
} from '../../src/api/DataConnect';
325
import { app } from '../util';
426
import { queryRef } from '../../src';
527
describe.only('Transport Options', () => {
6-
it('should return false if transport options are not equal', () => {
7-
const transportOptions1: TransportOptions = {
8-
host: 'h',
9-
port: 1,
10-
sslEnabled: false
11-
};
12-
const transportOptions2: TransportOptions = {
13-
host: 'h2',
14-
port: 2,
15-
sslEnabled: false
16-
};
17-
expect(areTransportOptionsEqual(transportOptions1, transportOptions2)).to.eq(false);
28+
it('should return false if transport options are not equal', () => {
29+
const transportOptions1: TransportOptions = {
30+
host: 'h',
31+
port: 1,
32+
sslEnabled: false
33+
};
34+
const transportOptions2: TransportOptions = {
35+
host: 'h2',
36+
port: 2,
37+
sslEnabled: false
38+
};
39+
expect(
40+
areTransportOptionsEqual(transportOptions1, transportOptions2)
41+
).to.eq(false);
42+
});
43+
it('should return true if transport options are equal', () => {
44+
const transportOptions1: TransportOptions = {
45+
host: 'h',
46+
port: 1,
47+
sslEnabled: false
48+
};
49+
const transportOptions2: TransportOptions = {
50+
host: 'h',
51+
port: 1,
52+
sslEnabled: false
53+
};
54+
expect(
55+
areTransportOptionsEqual(transportOptions1, transportOptions2)
56+
).to.eq(true);
57+
});
58+
it.only('should throw if emulator is connected to with new transport options', () => {
59+
const dc = getDataConnect(app, {
60+
connector: 'c',
61+
location: 'l',
62+
service: 's'
1863
});
19-
it('should return true if transport options are equal', () => {
20-
const transportOptions1: TransportOptions = {
21-
host: 'h',
22-
port: 1,
23-
sslEnabled: false
24-
};
25-
const transportOptions2: TransportOptions = {
26-
host: 'h',
27-
port: 1,
28-
sslEnabled: false
29-
};
30-
expect(areTransportOptionsEqual(transportOptions1, transportOptions2)).to.eq(true);
64+
expect(() => connectDataConnectEmulator(dc, 'h', 80, false)).to.not.throw();
65+
queryRef(dc, 'query');
66+
expect(() => connectDataConnectEmulator(dc, 'h2', 80, false)).to.throw(
67+
'DataConnect instance already initialized!'
68+
);
69+
});
70+
it.only('should not throw if emulator is connected to with the same transport options', () => {
71+
const dc = getDataConnect(app, {
72+
connector: 'c',
73+
location: 'l',
74+
service: 's'
3175
});
32-
it.only('should throw if emulator is connected to with new transport options', () => {
33-
const dc = getDataConnect(app, {
34-
connector: 'c',
35-
location: 'l',
36-
service: 's'
37-
});
38-
expect(() => connectDataConnectEmulator(dc, 'h', 80, false)).to.not.throw();
39-
queryRef(dc, 'query');
40-
expect(() => connectDataConnectEmulator(dc, 'h2', 80, false)).to.throw('DataConnect instance already initialized!');
41-
});
42-
it.only('should not throw if emulator is connected to with the same transport options', () => {
43-
const dc = getDataConnect(app, {
44-
connector: 'c',
45-
location: 'l',
46-
service: 's'
47-
});
48-
expect(() => connectDataConnectEmulator(dc, 'h', 80, false)).to.not.throw();
49-
queryRef(dc, 'query');
50-
expect(() => connectDataConnectEmulator(dc, 'h', 80, false)).to.not.throw();
51-
});
52-
});
76+
expect(() => connectDataConnectEmulator(dc, 'h', 80, false)).to.not.throw();
77+
queryRef(dc, 'query');
78+
expect(() => connectDataConnectEmulator(dc, 'h', 80, false)).to.not.throw();
79+
});
80+
});

0 commit comments

Comments
 (0)