Skip to content

Commit 27de10a

Browse files
authored
Add tests for App Check (#5)
Added tests for App Check. Additionally, made all `*TestResult` uniform in name (ie: `AuthTestResult` now just `TestResults`). This should speed up spinning up tests or the rest of the SDKs.
1 parent 92e9838 commit 27de10a

File tree

19 files changed

+224
-80
lines changed

19 files changed

+224
-80
lines changed

app/page.tsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,19 @@ export default async function Page() {
3030
<li><Link href="/tests/analytics/web_client">Analytics Web SDK client-side tests</Link></li>
3131
<li><Link href="/tests/analytics/web_ssr">Analytics Web SDK server-side tests</Link></li>
3232
</ul>
33+
<p />
3334
<li>App</li>
3435
<ul>
3536
<li><Link href="/tests/app/web_client">App Web SDK client-side tests</Link></li>
3637
<li><Link href="/tests/app/web_ssr">App Web SDK server-side tests</Link></li>
3738
</ul>
39+
<p />
40+
<li>AppCheck</li>
41+
<ul>
42+
<li><Link href="/tests/app_check/web_client">AppCheck Web SDK client-side tests</Link></li>
43+
<li><Link href="/tests/app_check/web_ssr">AppCheck Web SDK server-side tests</Link></li>
44+
</ul>
45+
<p />
3846
<li>Auth</li>
3947
<ul>
4048
<li><Link href="/tests/auth/web_client">Auth Web SDK client-side tests</Link></li>

app/tests/analytics/components/csr_test_runner.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,15 @@
1717
'use client'
1818

1919
import { useState, useEffect } from 'react'
20-
import { testApp, createAnalyticsTestResult } from '../lib/test';
20+
import { testApp, initializeTestResults } from '../lib/test';
2121
import ResultsDisplay from './results_display';
2222

2323
export default function ClientResults() {
2424
const [testStatus, setTestStatus] = useState<string>("running...");
25-
const [testAnalyticsResult, setTestAnalyticsResult] = useState(createAnalyticsTestResult());
25+
const [testResults, setTestResults] = useState(initializeTestResults());
2626
useEffect(() => {
2727
const asyncTest = async () => {
28-
setTestAnalyticsResult(await testApp());
28+
setTestResults(await testApp());
2929
setTestStatus("Complete!");
3030
}
3131
asyncTest().catch((e) => {
@@ -35,6 +35,6 @@ export default function ClientResults() {
3535
}, []);
3636

3737
return (
38-
<ResultsDisplay statusString={testStatus} testAppResult={testAnalyticsResult} />
38+
<ResultsDisplay statusString={testStatus} testResults={testResults} />
3939
);
4040
}

app/tests/analytics/components/results_display.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,15 @@
1515
* limitations under the License.
1616
*/
1717
import Link from 'next/link';
18-
export default function AnalyticsResultsDisplay({ statusString, testAppResult }) {
18+
export default function ResultsDisplay({ statusString, testResults }) {
1919
return (
2020
<>
2121
<h2 title="testStatus">{statusString}</h2>
22-
<h4 title="initializeAppResult">initializeAppResult: {testAppResult.initializeAppResult}</h4>
23-
<h4 title="isSupportedResult">isSupportedResult: {testAppResult.isSupportedResult}</h4>
24-
<h4 title="getAnalyticsResult">deleteAppResult: {testAppResult.getAnalyticsResult}</h4>
25-
<h4 title="logEventResult">logEventResult: {testAppResult.logEventResult}</h4>
26-
<h4 title="deleteAppResult">deleteAppResult: {testAppResult.deleteAppResult}</h4>
22+
<h4 title="initializeAppResult">initializeAppResult: {testResults.initializeAppResult}</h4>
23+
<h4 title="isSupportedResult">isSupportedResult: {testResults.isSupportedResult}</h4>
24+
<h4 title="getAnalyticsResult">deleteAppResult: {testResults.getAnalyticsResult}</h4>
25+
<h4 title="logEventResult">logEventResult: {testResults.logEventResult}</h4>
26+
<h4 title="deleteAppResult">deleteAppResult: {testResults.deleteAppResult}</h4>
2727
<p />
2828
<Link href="/">Back to test index</Link>
2929
</>

app/tests/analytics/lib/test.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,16 @@ import { getAnalytics, logEvent, isSupported } from 'firebase/analytics';
1919
import { firebaseConfig } from 'lib/firebase';
2020
import { OK, OK_SKIPPED, FAILED, sleep } from 'lib/util';
2121

22-
export type TestAnalyticsResult = {
22+
export type TestResults = {
2323
initializeAppResult: string,
2424
isSupportedResult: string,
2525
getAnalyticsResult: string,
2626
logEventResult: string,
2727
deleteAppResult: string
2828
};
2929

30-
export function createAnalyticsTestResult(): TestAnalyticsResult {
31-
const testAnalyticsResult: TestAnalyticsResult = {
30+
export function initializeTestResults(): TestResults {
31+
const testAnalyticsResult: TestResults = {
3232
initializeAppResult: FAILED,
3333
isSupportedResult: FAILED,
3434
getAnalyticsResult: FAILED,
@@ -38,8 +38,8 @@ export function createAnalyticsTestResult(): TestAnalyticsResult {
3838
return testAnalyticsResult;
3939
}
4040

41-
export async function testApp(isServerApp: boolean = false): Promise<TestAnalyticsResult> {
42-
const result: TestAnalyticsResult = createAnalyticsTestResult();
41+
export async function testApp(isServerApp: boolean = false): Promise<TestResults> {
42+
const result: TestResults = initializeTestResults();
4343
if (isServerApp) {
4444
try {
4545
// Note: Analytics isn't supported in node environments.

app/tests/analytics/web_ssr/page.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,19 @@
1515
* limitations under the License.
1616
*/
1717
import type { Metadata } from 'next'
18-
import { testApp, TestAnalyticsResult } from '../lib/test';
19-
import AnalyticsResultsDisplay from '../components/results_display';
18+
import { testApp, TestResults } from '../lib/test';
19+
import ResultsDisplay from '../components/results_display';
2020

2121
export const metadata: Metadata = {
2222
title: 'Analytics Web SDK SSR test'
2323
}
2424

2525
export default async function Page() {
26-
const testAnalyticsResult: TestAnalyticsResult = await testApp(/*isServer=*/true);
26+
const testResults: TestResults = await testApp(/*isServer=*/true);
2727
return (
2828
<>
2929
<h1>Analytics SSR Test results:</h1>
30-
<AnalyticsResultsDisplay statusString='Tests Complete!' testAppResult={testAnalyticsResult} />
30+
<ResultsDisplay statusString='Tests Complete!' testResults={testResults} />
3131
</>
3232
);
3333
}

app/tests/app/components/csr_test_runner.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,15 @@
1717
'use client'
1818

1919
import { useState, useEffect } from 'react'
20-
import { testApp, createTestAppResult } from '../lib/test';
20+
import { testApp, initializeTestResults } from '../lib/test';
2121
import ResultsDisplay from './results_display';
2222

2323
export default function CsrTestRunner() {
2424
const [testStatus, setTestStatus] = useState<string>("running...");
25-
const [testAppResult, setTestAppResult] = useState(createTestAppResult());
25+
const [testResults, setTestResults] = useState(initializeTestResults());
2626
useEffect(() => {
2727
const asyncTest = async () => {
28-
setTestAppResult(await testApp());
28+
setTestResults(await testApp());
2929
setTestStatus("Complete!");
3030
}
3131
asyncTest().catch((e) => {
@@ -35,6 +35,6 @@ export default function CsrTestRunner() {
3535
}, []);
3636

3737
return (
38-
<ResultsDisplay statusString={testStatus} testAppResult={testAppResult} />
38+
<ResultsDisplay statusString={testStatus} testResults={testResults} />
3939
);
4040
}

app/tests/app/components/results_display.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,15 @@
1515
* limitations under the License.
1616
*/
1717
import Link from 'next/link';
18-
export default function ResultsDisplay({ statusString, testAppResult }) {
18+
export default function ResultsDisplay({ statusString, testResults }) {
1919
return (
2020
<>
2121
<h2 title="testStatus">{statusString}</h2>
22-
<h4 title="initializeAppResult">initializeAppResult: {testAppResult.initializeAppResult}</h4>
23-
<h4 title="getAppResult">getAppResult: {testAppResult.getAppResult}</h4>
24-
<h4 title="deleteAppResult">deleteAppResult: {testAppResult.deleteAppResult}</h4>
25-
<h4 title="initializeServerAppResult">initializeServerAppResult: {testAppResult.initializeServerAppResult}</h4>
26-
<h4 title="deleteServerAppResult">deleteServerAppResult: {testAppResult.deleteServerAppResult}</h4>
22+
<h4 title="initializeAppResult">initializeAppResult: {testResults.initializeAppResult}</h4>
23+
<h4 title="getAppResult">getAppResult: {testResults.getAppResult}</h4>
24+
<h4 title="deleteAppResult">deleteAppResult: {testResults.deleteAppResult}</h4>
25+
<h4 title="initializeServerAppResult">initializeServerAppResult: {testResults.initializeServerAppResult}</h4>
26+
<h4 title="deleteServerAppResult">deleteServerAppResult: {testResults.deleteServerAppResult}</h4>
2727
<p />
2828
<Link href="/">Back to test index</Link>
2929
</>

app/tests/app/lib/test.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,27 +18,26 @@ import { getApp, deleteApp, initializeApp, initializeServerApp } from 'firebase/
1818
import { firebaseConfig } from 'lib/firebase';
1919
import { OK, OK_SKIPPED, FAILED } from 'lib/util';
2020

21-
export type TestAppResult = {
21+
export type TestResults = {
2222
initializeAppResult: string,
2323
getAppResult: string,
2424
deleteAppResult: string,
2525
initializeServerAppResult: string,
2626
deleteServerAppResult: string
2727
};
2828

29-
export function createTestAppResult(): TestAppResult {
30-
const testAppResult: TestAppResult = {
29+
export function initializeTestResults(): TestResults {
30+
return {
3131
initializeAppResult: FAILED,
3232
getAppResult: FAILED,
3333
deleteAppResult: FAILED,
3434
initializeServerAppResult: FAILED,
3535
deleteServerAppResult: FAILED
3636
};
37-
return testAppResult;
3837
}
3938

40-
export async function testApp(isServer: boolean = false): Promise<TestAppResult> {
41-
const result: TestAppResult = createTestAppResult();
39+
export async function testApp(isServer: boolean = false): Promise<TestResults> {
40+
const result: TestResults = initializeTestResults();
4241
try {
4342
const firebaseApp = initializeApp(firebaseConfig, "appTest");
4443
if (firebaseApp !== null) {

app/tests/app/web_ssr/page.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,19 @@
1515
* limitations under the License.
1616
*/
1717
import type { Metadata } from 'next'
18-
import { testApp, TestAppResult } from '../lib/test';
18+
import { testApp, TestResults } from '../lib/test';
1919
import ResultsDisplay from '../components/results_display';
2020

2121
export const metadata: Metadata = {
2222
title: 'App Web SDK SSR test'
2323
}
2424

2525
export default async function Page() {
26-
const testAppResult: TestAppResult = await testApp(/*isServer*/true);
26+
const testResults: TestResults = await testApp(/*isServer*/true);
2727
return (
2828
<>
2929
<h1>App SSR Test results:</h1>
30-
<ResultsDisplay statusString='Tests Complete!' testAppResult={testAppResult} />
30+
<ResultsDisplay statusString='Tests Complete!' testResults={testResults} />
3131
</>
3232
);
3333
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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+
'use client'
18+
19+
import { useState, useEffect } from 'react'
20+
import { testApp, initializeTestResults } from '../lib/test';
21+
import ResultsDisplay from './results_display';
22+
23+
export default function ClientResults() {
24+
const [testStatus, setTestStatus] = useState<string>("running...");
25+
const [testResults, setTestResults] = useState(initializeTestResults());
26+
useEffect(() => {
27+
const asyncTest = async () => {
28+
setTestResults(await testApp());
29+
setTestStatus("Complete!");
30+
}
31+
asyncTest().catch((e) => {
32+
console.error("Error encountered during testing: ", e);
33+
setTestStatus("Errored!");
34+
});
35+
}, []);
36+
37+
return (
38+
<ResultsDisplay statusString={testStatus} testResults={testResults} />
39+
);
40+
}

0 commit comments

Comments
 (0)