Skip to content

Commit

Permalink
remove parent level cancelations
Browse files Browse the repository at this point in the history
  • Loading branch information
glen committed Oct 26, 2023
1 parent a4f009d commit f7f7bcf
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 25 deletions.
6 changes: 2 additions & 4 deletions src/examples/get_trip_cancelations_batch.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,14 @@ describe('When creating trip cancelations', () => {
it('should save trip cancelations batch', () => {
api.logIn({ username: '[email protected]', password: 'securepassword' });

const tripCancelationBatchPromise = api.customer('SYNC').tripCancelationBatch({
cancelations: [
const tripCancelationBatchPromise = api.customer('SYNC').tripCancelationBatch([
{
customerId: 1,
},
{
customerId: 1,
},
],
})
])
.create()
.then(msg => msg); // Do things with msg

Expand Down
22 changes: 10 additions & 12 deletions src/mocks/tripCancelationBatches.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,18 @@ import fetchMock from 'fetch-mock';
import Client from '../Client';

const tripCancelationBatches = {
setUpSuccessfulMock: (client) => {
const fetchResponse = () => new Response(Client.toBlob(tripCancelationBatches.response));
const createResponse = () => new Response(Client.toBlob(tripCancelationBatches.response));
setUpSuccessfulMock: (client) => {
const fetchResponse = () => new Response(Client.toBlob(tripCancelationBatches.response));
const createResponse = () => new Response(Client.toBlob(tripCancelationBatches.response));

fetchMock
.get(client.resolve('/1/SYNC/serviceadjustments/cancelations'), fetchResponse)
.post(client.resolve('/1/SYNC/serviceadjustments/cancelations'), createResponse);
},
response: {
cancelations: [
{ href: '/1/SYNC/serviceadjustments/cancelations/1' },
{ href: '/1/SYNC/serviceadjustments/cancelations/2' },
fetchMock
.get(client.resolve('/1/SYNC/serviceadjustments/cancelations'), fetchResponse)
.post(client.resolve('/1/SYNC/serviceadjustments/cancelations'), createResponse);
},
response: [
{href: '/1/SYNC/serviceadjustments/cancelations/1'},
{href: '/1/SYNC/serviceadjustments/cancelations/2'},
],
},
};

export default tripCancelationBatches;
6 changes: 2 additions & 4 deletions src/resources/TripCancelationBatch.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,8 @@ class TripCancelationBatch extends Resource {
const {code, ...newProperties} = rest;
this.customerCode = code;
const hydrated = !Object.keys(newProperties).every(k => k === 'href' || k === 'customerCode');
const references = {
cancelations: newProperties.cancelations
&& newProperties.cancelations.map(m => new TripCancelation(this.client, m)),
};
const references = newProperties
&& newProperties.map(m => new TripCancelation(this.client, m));
Object.assign(this, newProperties, {
hydrated,
...references,
Expand Down
9 changes: 4 additions & 5 deletions src/resources/TripCancelationBatch.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ describe('When fetching trip cancelations based on customer', () => {

it('should resolve the promise', () => promise.should.be.fulfilled);
it('should set the href', () => promise.then(x => x.href).should.eventually.equal('/1/SYNC/serviceadjustments/cancelations'));
it('should set the trip cancelations', () => promise.then(x => x.cancelations.length).should.eventually.equal(2));
it('should set the trip cancelations', () => promise.then(x => x.length).should.eventually.equal(2));
it('should be hydrated', () => promise.then(x => x.hydrated).should.eventually.equal(true));
});

Expand All @@ -43,16 +43,15 @@ describe('When creating trip cancelations for a customer', () => {
let promise;
beforeEach(() => {
promise = new TripCancelationBatch(client, { code: 'SYNC',
...{
cancelations: [
...
[
{ href: '/1/SYNC/serviceadjustments/cancelations/1' },
{ href: '/1/SYNC/serviceadjustments/cancelations/2' },
],
},
}).create();
});

it('should resolve the promise', () => promise.should.be.fulfilled);
it('should set the message', () => promise.then(x => x.cancelations.length).should.eventually.equal(2));
it('should set the message', () => promise.then(x => x.length).should.eventually.equal(2));
it('should be hydrated', () => promise.then(x => x.hydrated).should.eventually.equal(true));
});

0 comments on commit f7f7bcf

Please sign in to comment.