|
| 1 | +// Copyright 2023 Google LLC |
| 2 | +// |
| 3 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +// you may not use this file except in compliance with the License. |
| 5 | +// You may obtain a copy of the License at |
| 6 | +// |
| 7 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +// |
| 9 | +// Unless required by applicable law or agreed to in writing, software |
| 10 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +// See the License for the specific language governing permissions and |
| 13 | +// limitations under the License. |
| 14 | + |
| 15 | +/* eslint-disable */ |
| 16 | + |
| 17 | +'use strict'; |
| 18 | + |
| 19 | +const path = require('path'); |
| 20 | +const {assert} = require('chai'); |
| 21 | +const {describe, it, after, before} = require('mocha'); |
| 22 | +const sinon = require('sinon'); |
| 23 | +const {Datastore} = require('@google-cloud/datastore'); |
| 24 | +const datastore = new Datastore(); |
| 25 | + |
| 26 | +const {queryFilterOr} = require('../queryFilterOr'); |
| 27 | +let taskKey1, taskKey2; |
| 28 | + |
| 29 | +describe('Creating a union query', () => { |
| 30 | + const stubConsole = function () { |
| 31 | + sinon.stub(console, 'error'); |
| 32 | + sinon.stub(console, 'log'); |
| 33 | + }; |
| 34 | + |
| 35 | + const restoreConsole = function () { |
| 36 | + console.log.restore(); |
| 37 | + console.error.restore(); |
| 38 | + }; |
| 39 | + |
| 40 | + beforeEach(stubConsole); |
| 41 | + afterEach(restoreConsole); |
| 42 | + |
| 43 | + before(async () => { |
| 44 | + taskKey1 = datastore.key('Task'); |
| 45 | + const entity1 = { |
| 46 | + key: taskKey1, |
| 47 | + data: { |
| 48 | + description: 'Buy milk', |
| 49 | + }, |
| 50 | + }; |
| 51 | + |
| 52 | + taskKey2 = datastore.key('Task'); |
| 53 | + const entity2 = { |
| 54 | + key: taskKey2, |
| 55 | + data: { |
| 56 | + description: 'Feed cats', |
| 57 | + }, |
| 58 | + }; |
| 59 | + |
| 60 | + await datastore.upsert(entity1); |
| 61 | + await datastore.upsert(entity2); |
| 62 | + }); |
| 63 | + |
| 64 | + after(async () => { |
| 65 | + await datastore.delete(taskKey1); |
| 66 | + await datastore.delete(taskKey2); |
| 67 | + }); |
| 68 | + |
| 69 | + it('should get a combination of items from the Datastore', async () => { |
| 70 | + await queryFilterOr(); |
| 71 | + assert.include(console.log.firstCall.args[0], 'Entity'); |
| 72 | + }); |
| 73 | +}); |
0 commit comments