How to use the api/utils/testing_db.id function in api

To help you get started, we’ve selected a few api examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github huridocs / uwazi / app / api / search / specs / fixtures.js View on Github external
/* eslint-disable max-len */
import db from 'api/utils/testing_db';

const batmanFinishesId = db.id();
const unpublishedId = db.id();
const syncPropertiesEntityId = db.id();
const templateId = db.id();
const userId = db.id();

export default {
  entities: [
    { _id: batmanFinishesId, sharedId: 'shared', template: templateId, language: 'en', title: 'Batman finishes', published: true, user: userId },
    { _id: unpublishedId, sharedId: 'unpublished', template: db.id(), language: 'en', title: 'unpublished', published: false, user: userId },
    { _id: db.id(), sharedId: 'shared', language: 'es', title: 'Penguin almost done', creationDate: 1, published: true },
    {
      _id: db.id(), sharedId: 'shared', language: 'pt', title: 'Penguin almost done', creationDate: 1, published: true, metadata: { text: 'test' }
    },
    //select/multiselect/date sync
    { _id: syncPropertiesEntityId, template: templateId, sharedId: 'shared1', language: 'en', title: 'EN', published: true, metadata: { text: 'text' } },
    { _id: db.id(), template: templateId, sharedId: 'shared1', language: 'es', title: 'ES', creationDate: 1, published: true, metadata: { text: 'text' } },
    { _id: db.id(), template: templateId, sharedId: 'shared1', language: 'pt', title: 'PT', creationDate: 1, published: true, metadata: { text: 'text' } }
github huridocs / uwazi / app / api / sync / specs / fixtures.js View on Github external
/* eslint-disable max-len */
import db from 'api/utils/testing_db';

const oldDoc1 = db.id();
const oldDoc2 = db.id();

const newDoc1 = db.id();
const newDoc2 = db.id();
const newDoc3 = db.id();
const newDoc4 = db.id();
const newDoc5 = db.id();
const newDoc6 = db.id();
const newDoc7 = db.id();
const newDoc8 = db.id();
const newDoc9 = db.id();
const newDoc10 = db.id();

const template1 = db.id();

const template1Property1 = db.id();
const template1Property2 = db.id();
const template1Property3 = db.id();
const template1PropertyThesauri1Select = db.id();
const template1PropertyThesauri2Select = db.id();
const template1PropertyThesauri3MultiSelect = db.id();
const template1PropertyRelationship1 = db.id();
const template1PropertyRelationship2 = db.id();

const template2 = db.id();
github huridocs / uwazi / app / api / documents / specs / fixtures.js View on Github external
/* eslint-disable */
import db from 'api/utils/testing_db';

const batmanFinishesId = db.id();
const syncPropertiesEntityId = db.id();
const templateId = db.id();
const referenceId = db.id();

export default {
  entities: [
    {_id: batmanFinishesId, sharedId: 'shared', template: templateId, language: 'en', title: 'Batman finishes', published: true, user: {username: 'username'}, file: {filename: '8202c463d6158af8065022d9b5014cc1.pdf', originalname: 'Batman original.jpg'}},
    {_id: db.id(), sharedId: 'shared', language: 'es', title: 'Penguin almost done', creationDate: 1, published: true, user: {username: 'username'}, file: {filename: '8202c463d6158af8065022d9b5014ccb.pdf', fullText: 'fullText'}, attachments: [{filename: '8202c463d6158af8065022d9b5014ccc.pdf'}]},
    {
      _id: db.id(), sharedId: 'shared', language: 'pt', title: 'Penguin almost done', creationDate: 1, published: true, metadata: {text: 'test'},
      user: {username: 'username'}
    },
    //select/multiselect/date sync
    {_id: syncPropertiesEntityId, template: templateId, sharedId: 'shared1', language: 'en', title: 'EN', published: true, metadata: {text: 'text'}, user: {username: 'username'}},
    {_id: db.id(), template: templateId, sharedId: 'shared1', language: 'es', title: 'ES', creationDate: 1, published: true, metadata: {text: 'text'}, user: {username: 'username'}},
    {_id: db.id(), template: templateId, sharedId: 'shared1', language: 'pt', title: 'PT', creationDate: 1, published: true, metadata: {text: 'text'}, user: {username: 'username'}}
  ],
  settings: [
    {_id: db.id(), languages: [{key: 'es'}, {key: 'pt'}, {key: 'en'}]}
  ],
  templates: [
    {_id: templateId, name: 'template_test', properties: [
      {type: 'text', name: 'text'},
      {type: 'select', name: 'select'},
github huridocs / uwazi / app / api / odm / specs / model.spec.ts View on Github external
it('should be able to create when passing an _id and it does not exists', async () => {
      const extendedModel = instanceModel('tempSchema', testSchema);
      const id = testingDB.id();
      await extendedModel.save(({
        _id: id,
        name: 'document 1',
      } as unknown) as TestDoc);
      const [createdDocument] = await extendedModel.get({ _id: id });
      expect(createdDocument).toBeDefined();
    });
  });
github huridocs / uwazi / app / api / sync / specs / syncWorker.spec.js View on Github external
it('should sanitize the config to prevent deleted values to affect the process', async () => {
      const deletedTemplate = db.id();
      const deletedProperty = db.id();
      const deletedRelationtype = db.id();

      await syncWorkerWithConfig({
        templates: {
          [template1.toString()]: [template1Property1.toString(), deletedProperty.toString()],
          [deletedTemplate.toString()]: [],
          [template2.toString()]: [],
        },
        relationtypes: [relationtype1.toString(), deletedRelationtype.toString()]
      });

      const { callsCount: templateCalls } = getCallsToIds('templates', []);
      const { callsCount: relationtypesCalls } = getCallsToIds('relationtypes', []);

      expect(templateCalls).toBe(2);
github huridocs / uwazi / app / api / auth2fa / specs / usersUtils.spec.ts View on Github external
const verifyUserNotFound = async (method: string) => {
    await expectError(method, db.id(), 'any token', { code: 403, message: 'user not found' });
  };
github huridocs / uwazi / app / api / pages / specs / fixtures.js View on Github external
import db from 'api/utils/testing_db';

const pageToUpdate = db.id();

export default {
  pages: [
    { _id: db.id(), sharedId: '1', language: 'es', title: 'Batman finishes', user: { username: 'user' } },
    { _id: db.id(), sharedId: '1', language: 'en', title: 'Batman finishes', user: { username: 'user' } },
    { _id: pageToUpdate, sharedId: '2', language: 'es', title: 'Penguin almost done', creationDate: 1, user: { username: 'user' } },
    { _id: db.id(), sharedId: '2', language: 'fr', title: 'Right there', user: { username: 'user' } }
  ],

  settings: [
    { _id: db.id(), languages: [{ key: 'es', default: true }, { key: 'pt' }, { key: 'en' }] }
  ]
};

export {
  pageToUpdate
github huridocs / uwazi / app / api / thesauris / specs / fixtures.js View on Github external
{ id: '2.1', label: 'batman' },
            { id: '2.2', label: 'spiderman' }
          ]
        },
        { id: '3', label: 'single value' },
      ]
    },
  ],
  templates: [
    { _id: db.id(entityTemplateId), name: 'entityTemplate', properties: [{}] },
    { _id: db.id(), name: 'documentTemplate', properties: [{}] }
  ],
  entities: [
    { _id: db.id(), sharedId: 'sharedId', type: 'entity', title: 'english entity', language: 'en', template: db.id(entityTemplateId), icon: 'Icon' },
    { _id: db.id(), sharedId: 'sharedId', type: 'entity', title: 'spanish entity', language: 'es', template: db.id(entityTemplateId), icon: 'Icon', published: true },
    { _id: db.id(), sharedId: 'other', type: 'entity', title: 'unpublished entity', language: 'es', template: db.id(entityTemplateId), published: false },
  ],
  settings: [
    { _id: db.id(), languages: [{ key: 'es', default: true }] }
  ],
};

export {
  dictionaryId,
  dictionaryIdToTranslate,
  dictionaryValueId,
  dictionaryWithValueGroups
};
github huridocs / uwazi / app / api / entities / specs / fixtures.js View on Github external
}
    },
    { _id: docId1, sharedId: 'shared', type: 'entity', language: 'es', title: 'Penguin almost done', creationDate: 1, published: true, file: { filename: '8202c463d6158af8065022d9b5014ccb.pdf' }, attachments: [{ filename: '8202c463d6158af8065022d9b5014ccc.pdf' }], fullText: { 1: 'text' } },
    { _id: docId2, sharedId: 'shared', type: 'entity', language: 'pt', title: 'Penguin almost done', creationDate: 1, published: true, metadata: { text: 'test' }, file: { filename: '8202c463d6158af8065022d9b5014cc1.pdf' } },
    { _id: unpublishedDocId, sharedId: 'other', type: 'entity', template: templateId, language: 'en', title: 'Unpublished entity', published: false, metadata: { property1: 'value1' } },
    //select/multiselect/date sync
    { _id: syncPropertiesEntityId, template: templateId, sharedId: 'shared1', type: 'entity', language: 'en', title: 'EN', published: true, metadata: { property1: 'text' }, file: { filename: 'nonexistent.pdf' } },
    { _id: db.id(), template: templateId, sharedId: 'shared1', type: 'entity', language: 'es', title: 'ES', creationDate: 1, published: true, metadata: { property1: 'text' }, file: { filename: 'nonexistent.pdf' }, fullText: { 1: 'text' } },
    { _id: db.id(), template: templateId, sharedId: 'shared1', type: 'entity', language: 'pt', title: 'PT', creationDate: 1, published: true, metadata: { property1: 'text' }, file: { filename: 'nonexistent.pdf' } },
    //docs to change metadata property names
    { _id: db.id(), template: templateChangingNames, sharedId: 'shared10', type: 'entity', language: 'pt', title: 'PT', creationDate: 1, published: true, metadata: { property1: 'value1', property2: 'value2', property3: 'value3' }, file: { filename: '123.pdf' } },
    { _id: db.id(), template: templateChangingNames, sharedId: 'shared10', type: 'entity', language: 'pt', title: 'PT', creationDate: 1, published: true, metadata: { property1: 'value1', property2: 'value2', property3: 'value3' }, file: { filename: '123.pdf' } },
    //docs using entity as thesauri
    { title: 'title', _id: db.id(), template: templateWithEntityAsThesauri, sharedId: 'multiselect', type: 'entity', language: 'en', metadata: { multiselect: ['shared', 'value1'] }, file: { filename: '123.pdf' } },
    { title: 'title', _id: db.id(), template: templateWithEntityAsThesauri2, sharedId: 'multiselect', type: 'entity', language: 'es', metadata: { multiselect2: ['shared', 'value2'] }, file: { filename: '123.pdf' }, fullText: { 1: 'text' } },
    { title: 'title', _id: db.id(), template: templateWithEntityAsThesauri, sharedId: 'select', type: 'entity', language: 'en', metadata: { select: 'shared' }, file: { filename: '123.pdf' } },
    { title: 'title', _id: db.id(), template: templateWithEntityAsThesauri2, sharedId: 'select', type: 'entity', language: 'es', metadata: { select2: 'shared' }, file: { filename: '123.pdf' }, fullText: { 1: 'text' } },
    { title: 'title', _id: db.id(), template: db.id(), sharedId: 'otherTemplateWithMultiselect', type: 'entity', language: 'es', metadata: { select2: 'value' }, file: { filename: '123.pdf' }, fullText: { 1: 'text' } },
    { title: 'title', _id: db.id(), template: templateWithOnlySelect, sharedId: 'otherTemplateWithSelect', type: 'entity', language: 'es', metadata: { select: 'shared10' }, file: { filename: '123.pdf' }, fullText: { 1: 'text' } },
    { title: 'title', _id: db.id(), template: templateWithOnlyMultiselect, sharedId: 'otherTemplateWithMultiselect', type: 'entity', language: 'es', metadata: { multiselect: ['value1', 'multiselect'] }, file: { filename: '123.pdf' } },
    { sharedId: 'shared2', language: 'en' },
    { sharedId: 'source2', language: 'en' }
  ],
  settings: [
    { _id: db.id(), languages: [{ key: 'es', default: true }, { key: 'pt' }, { key: 'en' }] }
  ],
  templates: [
    { _id: templateId,
      name: 'template_test',
      properties: [
        { type: 'text', name: 'text' },
        { type: 'select', name: 'select' },
github huridocs / uwazi / app / api / semanticsearch / specs / fixtures.js View on Github external
import db from 'api/utils/testing_db';

const search1Id = db.id();
const search2Id = db.id();
const search3Id = db.id();
const searchIdForFilters = db.id();
const doc1ObjectId = db.id();
const doc1Id = 'doc1';
const docWithoutTextId = 'docWithoutText';
const template1Id = db.id();

export default {
  semanticsearches: [
    {
      _id: search1Id,
      searchTerm: 'legal',
      status: 'inProgress',
      language: 'en',
      documents: [
        { sharedId: doc1Id, status: 'pending' },
        { sharedId: docWithoutTextId, status: 'pending' }
      ]
    },
    {
      _id: search2Id,
      searchTerm: 'injustice',