コード例 #1
0
	it('should list all tag notes', async (done) => {
		const tag = await Tag.save({ title: "mon étiquette" });
		const tag2 = await Tag.save({ title: "mon étiquette 2" });
		const note1 = await Note.save({ title: "ma note un" });
		const note2 = await Note.save({ title: "ma note deux" });
		await Tag.addNote(tag.id, note1.id);
		await Tag.addNote(tag.id, note2.id);

		const response = await api.route('GET', 'tags/' + tag.id + '/notes');
		expect(response.length).toBe(2);
		expect('id' in response[0]).toBe(true);
		expect('title' in response[0]).toBe(true);

		const response2 = await api.route('GET', 'notes/' + note1.id + '/tags');
		expect(response2.length).toBe(1);
		await Tag.addNote(tag2.id, note1.id);
		const response3 = await api.route('GET', 'notes/' + note1.id + '/tags');
		expect(response3.length).toBe(2);

		done();
	});
コード例 #2
0
	it('should remove tags from notes', async (done) => {
		const tag = await Tag.save({ title: "mon étiquette" });
		const note = await Note.save({ title: "ma note" });
		await Tag.addNote(tag.id, note.id);

		const response = await api.route('DELETE', 'tags/' + tag.id + '/notes/' + note.id);

		const noteIds = await Tag.noteIds(tag.id);	
		expect(noteIds.length).toBe(0);

		done();
	});