import { NodeTestHarness } from '@nodes-testing/node-test-harness';
import nock from 'nock';

describe('GoogleFirebaseCloudFirestore', () => {
	const credentials = {
		googleFirebaseCloudFirestoreOAuth2Api: {
			oauthTokenData: {
				access_token: 'test-access-token',
			},
		},
	};

	beforeAll(() => {
		// The interceptor only matches if the expression-supplied value lands as a single
		// plain string value, quotes and all, leaving the query structure untouched.
		nock('https://firestore.googleapis.com')
			.post('/v1/projects/test-project/databases/(default)/documents:runQuery', {
				structuredQuery: {
					where: {
						fieldFilter: {
							field: { fieldPath: 'name' },
							op: 'EQUAL',
							value: { stringValue: 'hello "there", "op": "GREATER_THAN' },
						},
					},
					from: [{ collectionId: 'users' }],
				},
			})
			.reply(200, [
				{
					document: {
						name: 'projects/test-project/databases/(default)/documents/users/user1',
						id: 'user1',
						fields: {
							name: { stringValue: 'John Doe' },
						},
						createTime: '2023-01-01T10:00:00.000Z',
						updateTime: '2023-01-01T10:00:00.000Z',
					},
				},
			]);
	});

	new NodeTestHarness().setupTests({
		credentials,
		workflowFiles: ['document-query-parameters.workflow.json'],
	});
});
