UNPKG

16.9 kBJavaScriptView Raw
1/*
2 * Licensed under the Apache License, Version 2.0 (the "License");
3 * you may not use this file except in compliance with the License.
4 * You may obtain a copy of the License at
5 *
6 * http://www.apache.org/licenses/LICENSE-2.0
7 *
8 * Unless required by applicable law or agreed to in writing, software
9 * distributed under the License is distributed on an "AS IS" BASIS,
10 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 * See the License for the specific language governing permissions and
12 * limitations under the License.
13 */
14
15'use strict';
16
17let request = require('supertest');
18const decache = require('decache');
19const chai = require('chai');
20
21let server;
22
23chai.should();
24
25const body = require('./data/latedeliveryandpenalty/request.json');
26const state = require('./data/latedeliveryandpenalty/state.json');
27const triggerData = require('./data/latedeliveryandpenalty/data.json');
28const responseBody = {
29 '$class': 'org.accordproject.latedeliveryandpenalty.LateDeliveryAndPenaltyResponse',
30 penalty: 4,
31 buyerMayTerminate: true,
32};
33
34const parseBody = {
35 '$class': 'org.accordproject.latedeliveryandpenalty.TemplateModel',
36 'clauseId': '1',
37 'forceMajeure': true,
38 'penaltyDuration': {
39 '$class': 'org.accordproject.time.Duration',
40 'amount': 9,
41 'unit': 'days'
42 },
43 'penaltyPercentage': 7,
44 'capPercentage': 2,
45 'termination': {
46 '$class': 'org.accordproject.time.Duration',
47 'amount': 2,
48 'unit': 'weeks'
49 },
50 'fractionalPart': 'days'
51};
52const parseCopyrightBody = {
53 '$class': 'org.accordproject.copyrightlicense.CopyrightLicenseContract',
54 'contractId': '1',
55 'effectiveDate': '2018-01-01T00:00:00.000-04:00',
56 'licensee': 'resource:org.accordproject.party.Party#Me',
57 'licenseeState': 'NY',
58 'licenseeEntityType': 'Company',
59 'licenseeAddress': '1 Broadway',
60 'licensor': 'resource:org.accordproject.party.Party#Myself',
61 'licensorState': 'NY',
62 'licensorEntityType': 'Company',
63 'licensorAddress': '2 Broadway',
64 'territory': 'United States',
65 'purposeDescription': 'stuff',
66 'workDescription': 'other stuff',
67 'paymentClause': {
68 '$class': 'org.accordproject.copyrightlicense.PaymentClause',
69 'clauseId': '2',
70 'amountText': 'one hundred US Dollars',
71 'amount': {
72 '$class': 'org.accordproject.money.MonetaryAmount',
73 'doubleValue': 100,
74 'currencyCode': 'USD'
75 },
76 'paymentProcedure': 'bank transfer'
77 }
78};
79const draftLateText = 'Late Delivery and Penalty. In case of delayed delivery except for Force Majeure cases, the Seller shall pay to the Buyer for every 9 days of delay penalty amounting to 7.0% of the total value of the Equipment whose delivery has been delayed. Any fractional part of a days is to be considered a full days. The total amount of penalty shall not however, exceed 2.0% of the total value of the Equipment involved in late delivery. If the delay is more than 2 weeks, the Buyer is entitled to terminate this Contract.';
80const draftCopyrightText = `Copyright License Agreement
81
82This COPYRIGHT LICENSE AGREEMENT (the "Agreement"), dated as of 01/01/2018 (the "Effective Date"), is made by and between "Me" ("Licensee"), a "NY" "Company" with offices located at "1 Broadway", and "Myself" ("Licensor"), a "NY" "Company" with offices located at "2 Broadway".
83
84WHEREAS, Licensor solely and exclusively owns or controls the Work (as defined below) and wishes to grant to Licensee a license to the Work, and Licensee wishes to obtain a license to the Work for the uses and purposes described herein, each subject to the terms and conditions set forth herein.
85
86NOW, THEREFORE, in consideration of the mutual covenants, terms, and conditions set forth herein, and for other good and valuable consideration, the receipt and sufficiency of which are hereby acknowledged, the parties agree as follows:
87
88License.
89
90Grant of Rights. Subject to the terms and conditions of this Agreement, Licensor hereby grants to Licensee and its affiliates during the Term (as defined below) an exclusive, transferable right and license in the "United States" (the "Territory"), to reproduce, publicly perform, display, transmit, and distribute the Work, including translate, alter, modify, and create derivative works of the Work, through all media now known or hereinafter developed for purposes of "stuff". The "Work" is defined as "other stuff".
91
92Permissions. Licensor has obtained from all persons and entities who are, or whose trademark or other property is, identified, depicted, or otherwise referred to in the Work, such written and signed licenses, permissions, waivers, and consents (collectively, "Permissions" and each, individually, a "Permission"), including those relating to publicity, privacy, and any intellectual property rights, as are or reasonably may be expected to be necessary for Licensee to exercise its rights in the Work as permitted under this Agreement, without incurring any payment or other obligation to, or otherwise violating any right of, any such person or entity.
93
94Copyright Notices. Licensee shall ensure that its use of the Work is marked with the appropriate copyright notices specified by Licensor in a reasonably prominent position in the order and manner provided by Licensor. Licensee shall abide by the copyright laws and what are considered to be sound practices for copyright notice provisions in the Territory. Licensee shall not use any copyright notices that conflict with, confuse, or negate the notices Licensor provides and requires hereunder.
95
96{{#clause paymentClause}}
97Payment. As consideration in full for the rights granted herein, Licensee shall pay Licensor a one-time fee in the amount of "one hundred US Dollars" (100.0 USD) upon execution of this Agreement, payable as follows: "bank transfer".
98{{/clause}}
99
100General.
101
102Interpretation. For purposes of this Agreement, (a) the words "include," "includes," and "including" are deemed to be followed by the words "without limitation"; (b) the word "or" is not exclusive; and (c) the words "herein," "hereof," "hereby," "hereto," and "hereunder" refer to this Agreement as a whole. This Agreement is intended to be construed without regard to any presumption or rule requiring construction or interpretation against the party drafting an instrument or causing any instrument to be drafted.
103
104Entire Agreement. This Agreement, including and together with any related attachments, constitutes the sole and entire agreement of the parties with respect to the subject matter contained herein, and supersedes all prior and contemporaneous understandings, agreements, representations, and warranties, both written and oral, with respect to such subject matter.
105
106Severability. If any term or provision of this Agreement is invalid, illegal, or unenforceable in any jurisdiction, such invalidity, illegality, or unenforceability will not affect the enforceability of any other term or provision of this Agreement, or invalidate or render unenforceable such term or provision in any other jurisdiction. [Upon a determination that any term or provision is invalid, illegal, or unenforceable, [the parties shall negotiate in good faith to/the court may] modify this Agreement to effect the original intent of the parties as closely as possible in order that the transactions contemplated hereby be consummated as originally contemplated to the greatest extent possible.]
107
108Assignment. Licensee may freely assign or otherwise transfer all or any of its rights, or delegate or otherwise transfer all or any of its obligations or performance, under this Agreement without Licensor's consent. This Agreement is binding upon and inures to the benefit of the parties hereto and their respective permitted successors and assigns.`;
109
110const draftCopyrightTextUnquoted = `Copyright License Agreement
111
112This COPYRIGHT LICENSE AGREEMENT (the "Agreement"), dated as of 01/01/2018 (the "Effective Date"), is made by and between Me ("Licensee"), a NY Company with offices located at 1 Broadway, and Myself ("Licensor"), a NY Company with offices located at 2 Broadway.
113
114WHEREAS, Licensor solely and exclusively owns or controls the Work (as defined below) and wishes to grant to Licensee a license to the Work, and Licensee wishes to obtain a license to the Work for the uses and purposes described herein, each subject to the terms and conditions set forth herein.
115
116NOW, THEREFORE, in consideration of the mutual covenants, terms, and conditions set forth herein, and for other good and valuable consideration, the receipt and sufficiency of which are hereby acknowledged, the parties agree as follows:
117
118License.
119
120Grant of Rights. Subject to the terms and conditions of this Agreement, Licensor hereby grants to Licensee and its affiliates during the Term (as defined below) an exclusive, transferable right and license in the United States (the "Territory"), to reproduce, publicly perform, display, transmit, and distribute the Work, including translate, alter, modify, and create derivative works of the Work, through all media now known or hereinafter developed for purposes of stuff. The "Work" is defined as other stuff.
121
122Permissions. Licensor has obtained from all persons and entities who are, or whose trademark or other property is, identified, depicted, or otherwise referred to in the Work, such written and signed licenses, permissions, waivers, and consents (collectively, "Permissions" and each, individually, a "Permission"), including those relating to publicity, privacy, and any intellectual property rights, as are or reasonably may be expected to be necessary for Licensee to exercise its rights in the Work as permitted under this Agreement, without incurring any payment or other obligation to, or otherwise violating any right of, any such person or entity.
123
124Copyright Notices. Licensee shall ensure that its use of the Work is marked with the appropriate copyright notices specified by Licensor in a reasonably prominent position in the order and manner provided by Licensor. Licensee shall abide by the copyright laws and what are considered to be sound practices for copyright notice provisions in the Territory. Licensee shall not use any copyright notices that conflict with, confuse, or negate the notices Licensor provides and requires hereunder.
125
126{{#clause paymentClause}}
127Payment. As consideration in full for the rights granted herein, Licensee shall pay Licensor a one-time fee in the amount of one hundred US Dollars (100.0 USD) upon execution of this Agreement, payable as follows: bank transfer.
128{{/clause}}
129
130General.
131
132Interpretation. For purposes of this Agreement, (a) the words "include," "includes," and "including" are deemed to be followed by the words "without limitation"; (b) the word "or" is not exclusive; and (c) the words "herein," "hereof," "hereby," "hereto," and "hereunder" refer to this Agreement as a whole. This Agreement is intended to be construed without regard to any presumption or rule requiring construction or interpretation against the party drafting an instrument or causing any instrument to be drafted.
133
134Entire Agreement. This Agreement, including and together with any related attachments, constitutes the sole and entire agreement of the parties with respect to the subject matter contained herein, and supersedes all prior and contemporaneous understandings, agreements, representations, and warranties, both written and oral, with respect to such subject matter.
135
136Severability. If any term or provision of this Agreement is invalid, illegal, or unenforceable in any jurisdiction, such invalidity, illegality, or unenforceability will not affect the enforceability of any other term or provision of this Agreement, or invalidate or render unenforceable such term or provision in any other jurisdiction. [Upon a determination that any term or provision is invalid, illegal, or unenforceable, [the parties shall negotiate in good faith to/the court may] modify this Agreement to effect the original intent of the parties as closely as possible in order that the transactions contemplated hereby be consummated as originally contemplated to the greatest extent possible.]
137
138Assignment. Licensee may freely assign or otherwise transfer all or any of its rights, or delegate or otherwise transfer all or any of its obligations or performance, under this Agreement without Licensor's consent. This Agreement is binding upon and inures to the benefit of the parties hereto and their respective permitted successors and assigns.`;
139
140describe('cicero-server environment', () => {
141 beforeEach(()=>{
142 process.env.CICERO_DIR = './test/data1';
143 });
144
145 it('/should fail to start the server without CICERO_DIR defined', async () => {
146 delete process.env.CICERO_DIR;
147 (() => require('../app')).should.throw('You must set the CICERO_DIR environment variable.');
148 decache('../app');
149 });
150});
151
152describe('cicero-server', () => {
153
154 before(()=>{
155 process.env.CICERO_DIR = './test/data';
156 server = require('../app');
157 request = request(server);
158 });
159
160 it('/should trigger a simple stateless request (ergo)', async () => {
161 return request.post('/trigger/latedeliveryandpenalty')
162 .send({ 'request' : body, 'data' : triggerData })
163 .expect(200)
164 .expect('Content-Type',/json/)
165 .then(response => {
166 response.body.response.should.include(responseBody);
167 response.body.should.not.have.property('state');
168 });
169 });
170
171 it('/should fail to trigger without data', async () => {
172 return request.post('/trigger/latedeliveryandpenalty')
173 .send({ 'request' : body })
174 .expect(500);
175 });
176
177 it('/should trigger a simple stateless request with a sample clause (ergo)', async () => {
178 return request.post('/trigger/latedeliveryandpenalty')
179 .send({ 'request' : body, 'data' : triggerData })
180 .expect(200)
181 .expect('Content-Type',/json/)
182 .then(response => {
183 response.body.response.should.include(responseBody);
184 response.body.should.not.have.property('state');
185 });
186 });
187
188 it('/should trigger a stateful request (ergo)', async () => {
189 return request.post('/trigger/latedeliveryandpenalty')
190 .send({
191 data: triggerData,
192 request: body,
193 state,
194 })
195 .expect(200)
196 .expect('Content-Type',/json/)
197 .then(response => {
198 response.body.response.should.include(responseBody);
199 response.body.state.should.include(state);
200 });
201 });
202
203 it('/should parse a template sample', async () => {
204 return request.post('/parse/latedeliveryandpenalty')
205 .send({ sample: draftLateText })
206 .expect(200)
207 .expect('Content-Type',/json/)
208 .then(response => {
209 delete response.body.clauseId;
210 const expectedBody = Object.assign({}, parseBody);
211 delete expectedBody.clauseId;
212 response.body.should.deep.include(expectedBody);
213 });
214 });
215
216 it('/should fail to parse without sample', async () => {
217 return request.post('/parse/latedeliveryandpenalty')
218 .send({})
219 .expect(500);
220 });
221
222 it('/should draft from a template', async () => {
223 return request.post('/draft/latedeliveryandpenalty')
224 .send({ data: parseBody })
225 .expect(200)
226 .expect('Content-Type',/text/)
227 .then(response => {
228 response.text.should.equal(draftLateText);
229 });
230 });
231
232 it('/should fail to draft without data', async () => {
233 return request.post('/draft/latedeliveryandpenalty')
234 .send({})
235 .expect(500);
236 });
237
238 it('/should draft from a template (copyright-notice)', async () => {
239 return request.post('/draft/copyright-license')
240 .send({ data: parseCopyrightBody })
241 .expect(200)
242 .expect('Content-Type',/text/)
243 .then(response => {
244 response.text.should.equal(draftCopyrightText);
245 });
246 });
247
248 it('/should draft from a template (copyright-notice)', async () => {
249 return request.post('/draft/copyright-license')
250 .send({ data: parseCopyrightBody, options: { unquoteVariables: true } })
251 .expect(200)
252 .expect('Content-Type',/text/)
253 .then(response => {
254 response.text.should.equal(draftCopyrightTextUnquoted);
255 });
256 });
257
258 after(() => {
259 server.close();
260 });
261});