Commit 202e8670 authored by Alejandro Celaya's avatar Alejandro Celaya Committed by Alejandro Celaya

Overwrite imported annotations URI with target document one

parent da7b94c9
......@@ -37,12 +37,12 @@ type ImportData = Pick<
* Return a copy of `ann` that contains only fields which can be preserved by
* an import performed on the client.
*/
function getImportData(ann: APIAnnotationData): ImportData {
function getImportData(ann: APIAnnotationData, uri?: string): ImportData {
return {
target: ann.target,
tags: ann.tags,
text: ann.text,
uri: ann.uri,
uri: uri ?? ann.uri,
document: ann.document,
extra: {
source: 'import',
......@@ -150,6 +150,7 @@ export class ImportAnnotationsService {
this._store.beginImport(anns.length);
const existingAnns = this._store.allAnnotations();
const currentUri = this._store.mainFrame()?.uri;
const importAnn = async (ann: APIAnnotationData): Promise<ImportResult> => {
const existingAnn = existingAnns.find(ex => duplicateMatch(ann, ex));
......@@ -158,8 +159,9 @@ export class ImportAnnotationsService {
}
try {
// Strip out all the fields that are ignored in an import.
const importData = getImportData(ann);
// Strip out all the fields that are ignored in an import, and overwrite
// the URI with current document's URI.
const importData = getImportData(ann, currentUri);
// Fill out the annotation with default values for the current user and
// group.
......
......@@ -13,6 +13,7 @@ describe('ImportAnnotationsService', () => {
allAnnotations: sinon.stub().returns([]),
beginImport: sinon.stub(),
completeImport: sinon.stub(),
mainFrame: sinon.stub(),
};
fakeToastMessenger = {
......@@ -100,6 +101,22 @@ describe('ImportAnnotationsService', () => {
});
});
it('overwrites annotation URI with current document one', async () => {
const newUri = 'new_document_uri';
fakeStore.mainFrame.returns({ uri: newUri });
const svc = createService();
const ann = generateAnnotation();
await svc.import([ann]);
assert.calledWith(fakeAnnotationsService.save, {
$tag: 'dummy',
...ann,
uri: newUri,
});
});
it('can save many annotations', async () => {
const svc = createService();
const anns = [];
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment