diff --git a/document-warehouse/delete-document-schema.js b/document-warehouse/delete-document-schema.js new file mode 100644 index 0000000000..1cbaaf7bf7 --- /dev/null +++ b/document-warehouse/delete-document-schema.js @@ -0,0 +1,59 @@ +/** Copyright 2023 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +'use strict'; + +async function main( + projectId = 'YOUR_PROJECT_ID', + location = 'YOUR_PROJECT_LOCATION', + documentSchemaId = 'YOUR_DOCUMENT_SCHEMA_ID' +) { + // [START contentwarehouse_delete_document_schema] + + /** + * TODO(developer): Uncomment these variables before running the sample. + * const projectId = 'YOUR_PROJECT_ID'; + * const location = 'YOUR_PROJECT_LOCATION'; // Format is 'us' or 'eu' + * const documentSchemaId = 'YOUR_DOCUMENT_SCHEMA_ID'; + */ + + // Import from google cloud + const {DocumentSchemaServiceClient} = + require('@google-cloud/contentwarehouse').v1; + + // Create service client + const serviceClient = new DocumentSchemaServiceClient(); + + // Delete Document Schema + async function deleteDocumentSchema() { + // Initialize request argument(s) + const request = { + // The full resource name of the location, e.g.: + // projects/{project_number}/locations/{location}/documentSchemas/{document_schema_id} + name: `projects/${projectId}/locations/${location}/documentSchemas/${documentSchemaId}`, + }; + + // Make Request + const response = await serviceClient.deleteDocumentSchema(request); + + // Print out response + console.log(`Document Schema Deleted: ${response}`); + } + + // [END contentwarehouse_delete_document_schema] + await deleteDocumentSchema(); +} + +exports.deleteDocumentSchema = main; diff --git a/document-warehouse/package.json b/document-warehouse/package.json index 79fd5217c8..dd04235ca8 100644 --- a/document-warehouse/package.json +++ b/document-warehouse/package.json @@ -4,12 +4,16 @@ "license": "Apache-2.0", "author": "Google LLC", "scripts": { - "test": "c8 mocha test/*.js --timeout 600000" + "test": "c8 mocha test/*.test.js --timeout 600000" }, "dependencies": { - "@google-cloud/contentwarehouse": "^0.5.1" + "@google-cloud/contentwarehouse": "^0.5.1", + "c8": "^8.0.1", + "chai": "^4.3.7", + "mocha": "^10.2.0", + "sinon": "^15.2.0" }, "devDependencies": { - "assert": "^2.0.0" + "assert": "^2.0.0" } } diff --git a/document-warehouse/test/delete-document-schema.test.js b/document-warehouse/test/delete-document-schema.test.js new file mode 100644 index 0000000000..41d8989015 --- /dev/null +++ b/document-warehouse/test/delete-document-schema.test.js @@ -0,0 +1,42 @@ +// Copyright 2023 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +'use strict'; + +const {describe, it} = require('mocha'); +const {assert} = require('chai'); +const sinon = require('sinon'); + +const text = 'Document Schema Deleted'; + +const {deleteDocumentSchema} = require('../delete-document-schema'); + +// TODO(developer): Fill in the variables below before running this test. +const projectId = 'YOUR_PROJECT_ID'; +const location = 'YOUR_PROJECT_LOCATION'; // Format is 'us' or 'eu' +const documentSchemaId = 'YOUR_DOCUMENT_SCHEMA_ID'; + +describe('Delete document schema', () => { + const stubConsole = function () { + sinon.stub(console, 'error'); + sinon.stub(console, 'log'); + }; + + beforeEach(stubConsole); + + it('should delete a document schema', async () => { + await deleteDocumentSchema(projectId, location, documentSchemaId); + assert.include(console.log.firstCall.args[0], text); + }); +});