Skip to content

Commit 36d311e

Browse files
committed
Fix #554
1 parent fbec75d commit 36d311e

File tree

3 files changed

+165
-54
lines changed

3 files changed

+165
-54
lines changed

docs/Drivers/JS/Reference/Collection/EdgeCollection.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ if (exists === false) {
7878

7979
## edgeCollection.save
8080

81-
`async edgeCollection.save(data, [fromId, toId]): Object`
81+
`async edgeCollection.save(data, [fromId, toId], [opts]): Object`
8282

8383
Creates a new edge between the documents _fromId_ and _toId_ with the given
8484
_data_ and returns an object containing the edge's metadata.

src/collection.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -780,7 +780,10 @@ export class EdgeCollection extends BaseCollection {
780780
method: "POST",
781781
path: "/_api/document",
782782
body: data,
783-
qs: { collection: this.name }
783+
qs: {
784+
...opts,
785+
collection: this.name
786+
}
784787
},
785788
res => res.body
786789
);

src/test/15-edge-collections.ts

Lines changed: 160 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -95,59 +95,167 @@ describe("EdgeCollection API", function() {
9595
});
9696
});
9797
describe("edgeCollection.save", () => {
98-
it("creates an edge in the collection", done => {
99-
let data = { _from: "d/1", _to: "d/2" };
100-
collection
101-
.save(data)
102-
.then(meta => {
103-
expect(meta).to.be.an("object");
104-
expect(meta)
105-
.to.have.property("_id")
106-
.that.is.a("string");
107-
expect(meta)
108-
.to.have.property("_rev")
109-
.that.is.a("string");
110-
expect(meta)
111-
.to.have.property("_key")
112-
.that.is.a("string");
113-
return collection.edge(meta._id).then(doc => {
114-
expect(doc).to.have.keys("_key", "_id", "_rev", "_from", "_to");
115-
expect(doc._id).to.equal(meta._id);
116-
expect(doc._key).to.equal(meta._key);
117-
expect(doc._rev).to.equal(meta._rev);
118-
expect(doc._from).to.equal(data._from);
119-
expect(doc._to).to.equal(data._to);
120-
});
121-
})
122-
.then(() => void done())
123-
.catch(done);
98+
it("creates an edge in the collection", async () => {
99+
const data = { chicken: "chicken", _from: "d/1", _to: "d/2" };
100+
const meta = await collection.save(data);
101+
expect(meta).to.be.an("object");
102+
expect(meta)
103+
.to.have.property("_id")
104+
.that.is.a("string");
105+
expect(meta)
106+
.to.have.property("_rev")
107+
.that.is.a("string");
108+
expect(meta)
109+
.to.have.property("_key")
110+
.that.is.a("string");
111+
const doc = await collection.edge(meta._id);
112+
expect(doc).to.have.keys(
113+
"chicken",
114+
"_key",
115+
"_id",
116+
"_rev",
117+
"_from",
118+
"_to"
119+
);
120+
expect(doc._id).to.equal(meta._id);
121+
expect(doc._key).to.equal(meta._key);
122+
expect(doc._rev).to.equal(meta._rev);
123+
expect(doc._from).to.equal(data._from);
124+
expect(doc._to).to.equal(data._to);
125+
expect(doc.chicken).to.equal(data.chicken);
124126
});
125-
it("uses the given _key if provided", done => {
126-
let data = { _key: "banana", _from: "d/1", _to: "d/2" };
127-
collection
128-
.save(data)
129-
.then(meta => {
130-
expect(meta).to.be.an("object");
131-
expect(meta)
132-
.to.have.property("_id")
133-
.that.is.a("string");
134-
expect(meta)
135-
.to.have.property("_rev")
136-
.that.is.a("string");
137-
expect(meta)
138-
.to.have.property("_key")
139-
.that.equals(data._key);
140-
return collection.edge(meta._id).then(doc => {
141-
expect(doc).to.have.keys("_key", "_id", "_rev", "_from", "_to");
142-
expect(doc._id).to.equal(meta._id);
143-
expect(doc._rev).to.equal(meta._rev);
144-
expect(doc._key).to.equal(data._key);
145-
expect(doc._from).to.equal(data._from);
146-
expect(doc._to).to.equal(data._to);
147-
});
148-
})
149-
.then(() => void done())
150-
.catch(done);
127+
it("uses the given _key if provided", async () => {
128+
const data = {
129+
chicken: "chicken",
130+
_key: "banana",
131+
_from: "d/1",
132+
_to: "d/2"
133+
};
134+
const meta = await collection.save(data);
135+
expect(meta).to.be.an("object");
136+
expect(meta)
137+
.to.have.property("_id")
138+
.that.is.a("string");
139+
expect(meta)
140+
.to.have.property("_rev")
141+
.that.is.a("string");
142+
expect(meta)
143+
.to.have.property("_key")
144+
.that.equals(data._key);
145+
const doc = await collection.edge(meta._id);
146+
expect(doc).to.have.keys(
147+
"chicken",
148+
"_key",
149+
"_id",
150+
"_rev",
151+
"_from",
152+
"_to"
153+
);
154+
expect(doc._id).to.equal(meta._id);
155+
expect(doc._rev).to.equal(meta._rev);
156+
expect(doc._key).to.equal(data._key);
157+
expect(doc._from).to.equal(data._from);
158+
expect(doc._to).to.equal(data._to);
159+
expect(doc.chicken).to.equal(data.chicken);
160+
});
161+
it("takes _from and _to as positional arguments", async () => {
162+
const data = { chicken: "chicken" };
163+
const from = "d/1";
164+
const to = "d/2";
165+
const meta = await collection.save(data, from, to);
166+
expect(meta).to.be.an("object");
167+
expect(meta)
168+
.to.have.property("_id")
169+
.that.is.a("string");
170+
expect(meta)
171+
.to.have.property("_rev")
172+
.that.is.a("string");
173+
expect(meta)
174+
.to.have.property("_key")
175+
.that.is.a("string");
176+
const doc = await collection.edge(meta._id);
177+
expect(doc).to.have.keys(
178+
"chicken",
179+
"_key",
180+
"_id",
181+
"_rev",
182+
"_from",
183+
"_to"
184+
);
185+
expect(doc.chicken).to.equal(data.chicken);
186+
expect(doc._id).to.equal(meta._id);
187+
expect(doc._key).to.equal(meta._key);
188+
expect(doc._rev).to.equal(meta._rev);
189+
expect(doc._from).to.equal(from);
190+
expect(doc._to).to.equal(to);
191+
});
192+
it("takes an options object", async () => {
193+
const data = { chicken: "chicken", _from: "d/1", _to: "d/2" };
194+
const meta = await collection.save(data, { returnNew: true });
195+
expect(meta).to.be.an("object");
196+
expect(meta)
197+
.to.have.property("_id")
198+
.that.is.a("string");
199+
expect(meta)
200+
.to.have.property("_rev")
201+
.that.is.a("string");
202+
expect(meta)
203+
.to.have.property("_key")
204+
.that.is.a("string");
205+
expect(meta)
206+
.to.have.property("new")
207+
.that.is.an("object");
208+
expect(meta.new).to.have.property("chicken", data.chicken);
209+
const doc = await collection.edge(meta._id);
210+
expect(doc).to.have.keys(
211+
"chicken",
212+
"_key",
213+
"_id",
214+
"_rev",
215+
"_from",
216+
"_to"
217+
);
218+
expect(doc.chicken).to.equal(data.chicken);
219+
expect(doc._id).to.equal(meta._id);
220+
expect(doc._key).to.equal(meta._key);
221+
expect(doc._rev).to.equal(meta._rev);
222+
expect(doc._from).to.equal(data._from);
223+
expect(doc._to).to.equal(data._to);
224+
});
225+
it("takes an options object with positional _from and _to", async () => {
226+
const data = { chicken: "chicken" };
227+
const from = "d/1";
228+
const to = "d/2";
229+
const meta = await collection.save(data, from, to, { returnNew: true });
230+
expect(meta).to.be.an("object");
231+
expect(meta)
232+
.to.have.property("_id")
233+
.that.is.a("string");
234+
expect(meta)
235+
.to.have.property("_rev")
236+
.that.is.a("string");
237+
expect(meta)
238+
.to.have.property("_key")
239+
.that.is.a("string");
240+
expect(meta)
241+
.to.have.property("new")
242+
.that.is.an("object");
243+
expect(meta.new).to.have.property("chicken", data.chicken);
244+
const doc = await collection.edge(meta._id);
245+
expect(doc).to.have.keys(
246+
"chicken",
247+
"_key",
248+
"_id",
249+
"_rev",
250+
"_from",
251+
"_to"
252+
);
253+
expect(doc.chicken).to.equal(data.chicken);
254+
expect(doc._id).to.equal(meta._id);
255+
expect(doc._key).to.equal(meta._key);
256+
expect(doc._rev).to.equal(meta._rev);
257+
expect(doc._from).to.equal(from);
258+
expect(doc._to).to.equal(to);
151259
});
152260
});
153261
describe("edgeCollection.traversal", () => {

0 commit comments

Comments
 (0)