• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript typeorm.Connection类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了TypeScript中typeorm.Connection的典型用法代码示例。如果您正苦于以下问题:TypeScript Connection类的具体用法?TypeScript Connection怎么用?TypeScript Connection使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了Connection类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。

示例1: async

  .get('/:id', async (req, res) => {
    vary(res, 'Accept-Language');

    const connection: Connection = req.app.locals.connection;
    const locale: Language = req.app.locals.locale;

    const photo = await connection
      .getRepository(Photo)
      .createQueryBuilder('photo')
      .innerJoinAndSelect("photo.translations", "translation", "translation.language = :locale", { locale })
      .select([
        "photo.id",
        "photo.src",
        "photo.views",
        "photo.datetime",
        "photo.group",
        "photo.width",
        "photo.height",
        "translation.field",
        "translation.value",
      ])
      .where("photo.id = :id", { id: req.params.id })
      .andWhere("photo.hidden = :hidden", { hidden: false })
      .getOne();

    await connection.getRepository(Photo).increment(photo, 'views', 1);

    res.send(photoDTO(photo));
  })
开发者ID:apuchenkin,项目名称:aws.photo.service,代码行数:29,代码来源:photo.ts


示例2: async

  .get('/:alias', async (req, res) => {
    vary(res, 'Accept-Language');
    res.set('Cache-Control', `public, max-age=${60 * 60 * 24 * 30}`)
    const connection: Connection = req.app.locals.connection;
    const locale: Language = req.app.locals.locale;

    const page = await connection
      .getRepository(Page)
      .createQueryBuilder('page')
      .leftJoinAndSelect("page.translations", "translation", "translation.language = :locale", { locale })
      .select([
        "page.alias",
        "translation.field",
        "translation.value",
      ])
      .where('page.alias = :alias', { alias: req.params.alias })
      .andWhere("page.hidden = :hidden", { hidden: false })
      .getOne();

    if (!page) {
      res.sendStatus(404);
    }

    res.send(pageDTO(page));
  });
开发者ID:apuchenkin,项目名称:aws.photo.service,代码行数:25,代码来源:page.ts


示例3: async

  .get('/', async (req, res) => {
    vary(res, 'Accept-Language');
    res.set('Cache-Control', `public, max-age=${60 * 60 * 24 * 30}`);

    const connection: Connection = req.app.locals.connection;
    const locale: Language = req.app.locals.locale;

    const categories = await connection
      .getRepository(Category)
      .createQueryBuilder('category')
      .leftJoinAndSelect("category.translations", "translation",
        "translation.language = :locale AND translation.field = :field", { locale, field: "title" })
      .leftJoinAndSelect("category.featured", "featured")
      .leftJoinAndSelect("category.parent", "parent")
      .select([
        "category.name",
        "category.date",
        "translation.field",
        "translation.value",
        "parent.name",
        "featured.src",
      ])
      .where("category.hidden = :hidden", { hidden: false })
      .getMany();

    res.send(unnest(categories).map(categoryDTO));
  })
开发者ID:apuchenkin,项目名称:aws.photo.service,代码行数:27,代码来源:category.ts


示例4: async

  .get('/', async (req, res) => {
    vary(res, 'Accept-Language');
    res.set('Cache-Control', `public, max-age=${60 * 60 * 24}`);

    const connection: Connection = req.app.locals.connection;

    const photos = await connection
      .getRepository(Photo)
      .createQueryBuilder('photo')
      .innerJoinAndSelect("photo.categories", "category", "category.name = :name", { name: req.params.category })
      .select([
        "photo.id",
        "photo.src",
        "photo.views",
        "photo.datetime",
        "photo.group",
      ])
      .where("photo.hidden = :hidden", { hidden: false })
      .andWhere("category.hidden = :hidden", { hidden: false })
      .orderBy('photo.datetime')
      .getMany();

    res.send(photos);
  })
开发者ID:apuchenkin,项目名称:aws.photo.service,代码行数:24,代码来源:photo.ts


示例5: describe

describe('WelcomeService', () => {
    let connection: Connection;
    let welcomeService: WelcomeService;

    beforeAll(async () => {
        const module = await createTestModule({
            imports: [DtoTransformerModule],
            providers: [WelcomeService]
        });
        connection = module.get<Connection>(Connection);
        welcomeService = module.get<WelcomeService>(WelcomeService);
    });

    beforeEach(async () => {
        await createTestData();
    });

    afterAll(async () => {
        await connection.close();
    });

    describe('generateGreeting', () => {
        it('should generate greeting', async () => {
            expect(welcomeService.generateGreeting('John Doe')).toBe('Hello, John Doe');
        });
    });

    describe('findAllFolders', () => {
        it('should find all folders', async () => {
            const loadedFolders = await welcomeService.findAllFolders();

            expect(loadedFolders).toBeArrayOfSize(8);
            expect(loadedFolders[0].id).toBeGreaterThanOrEqual(1);
            expect(loadedFolders[0].name).toBe('C:');
            expect(loadedFolders[0].dateAdded).toBeValidDate();
            expect(loadedFolders[0].children).toBeUndefined();
            expect(loadedFolders[0].parent).toBeUndefined();
        });
    });
});
开发者ID:pschild,项目名称:image-management-tool,代码行数:40,代码来源:welcome.service.spec.ts


示例6: describe

describe('SERVER ORM: ORMConnectionProvider', () => {
  let container: Container;
  let connection: Connection;

  beforeEach(async () => {
    container = new Container();
    container
      .bind<ConnectionOptions>(registry.ORMConnectionOptions)
      .toConstantValue({
        autoSchemaSync: true,
        type: 'sqlite',
        database: ':memory:'
      });
    container
      .bind<interfaces.Provider<Connection>>(registry.ORMConnectionProvider)
      .toProvider<Connection>(connectionProvider);
    connection = (await container.get<interfaces.Provider<Connection>>(
      registry.ORMConnectionProvider
    )()) as Connection;
  });

  afterEach(async () => {
    await connection.close();
    container.unbind(registry.ORMConnectionOptions);
    container.unbind(registry.ORMConnection);
  });

  it('should be connected to database', () => {
    expect(connection).toBeDefined();
    expect(connection.isConnected).toBeTruthy();
  });

  it('should return the same connection when one already exists', async () => {
    const newConnection = (await container.get<interfaces.Provider<Connection>>(
      registry.ORMConnectionProvider
    )()) as Connection;
    expect(connection).toBe(newConnection);
  });
});
开发者ID:patrickhousley,项目名称:xyzzy-mean,代码行数:39,代码来源:connection.provider.spec.ts


示例7: describe

describe('WelcomeController', () => {
    let connection: Connection;
    let welcomeController: WelcomeController;
    let welcomeService: WelcomeService;

    beforeAll(async () => {
        const module = await createTestModule({
            imports: [DtoTransformerModule],
            controllers: [WelcomeController],
            providers: [WelcomeService]
        });
        connection = module.get<Connection>(Connection);
        welcomeController = module.get<WelcomeController>(WelcomeController);
        welcomeService = module.get<WelcomeService>(WelcomeService);

        await createTestData();
    });

    beforeEach(async () => {
        await createTestData();
    });

    afterAll(async () => {
        await connection.close();
    });

    describe('findAllFolders', () => {
        it('should return an array of folders', async () => {
            jest.spyOn(welcomeService, 'findAllFolders').mockImplementation(() => [new Folder()]);
            const result = await welcomeController.test();

            expect(result).toBeDefined();
            expect(result).toBeArrayOfSize(1);
        });
    });
});
开发者ID:pschild,项目名称:image-management-tool,代码行数:36,代码来源:welcome.controller.spec.ts


示例8: describe

describe('SERVER CONTROLLERS: CardSetController', () => {
  let container: Container;
  let mockSettingsService: SettingsServiceAttributes;
  let mockLogger: winston.LoggerInstance;
  let connection: Connection;
  let app: express.Application;

  beforeEach(async () => {
    container = new Container();
    container.load(ormModule);

    // Services
    container
      .bind<SettingsServiceAttributes>(registry.SettingsService)
      .to(MockSettingsService)
      .inSingletonScope();
    mockSettingsService = container.get<SettingsServiceAttributes>(
      registry.SettingsService
    );
    mockSettingsService.loggerTransports = [
      new winston.transports.Console({
        silent: true
      })
    ];
    mockLogger = new winston.Logger();
    const loggerFactory: interfaces.FactoryCreator<winston.LoggerInstance> = (
      context: interfaces.Context
    ) => {
      return () => {
        return mockLogger;
      };
    };
    container
      .bind<interfaces.Factory<winston.LoggerInstance>>(registry.LoggerFactory)
      .toFactory(loggerFactory);

    // ORM
    container
      .bind<ConnectionOptions>(registry.ORMConnectionOptions)
      .toConstantValue({
        autoSchemaSync: true,
        type: 'sqlite',
        database: ':memory:'
      });
    connection = (await container.get<interfaces.Provider<Connection>>(
      registry.ORMConnectionProvider
    )()) as Connection;

    // Express configs
    container
      .bind<CardSetControllerAttributes>(CardSetController)
      .toSelf();
    app = express();
    useContainer(container);
    useExpressServer(app, {
      routePrefix: '/api',
      controllers: [CardSetController],
      development: true
    });
  });

  afterEach(async () => {
    await connection.close();
  });

  it('should be defined', () => {
    expect(app).toBeDefined();
  });

  describe('GET', () => {
    it('should respond successfully', async () => {
      /* tslint:disable:no-any */
      const cardSetRepositoryFind = jest
        .spyOn(connection.getRepository('CardSet'), 'find')
        .mockImplementation(async (entity: any): Promise<any> =>
          Promise.resolve([])
        );
      /* tslint:enable:no-any */
      await supertest(app).get('/api/cardSets').expect(200).then(response => {
        expect(response).toBeDefined();
        expect(response.body.cardSets).toBeDefined();
        expect(Array.isArray(response.body.cardSets)).toBe(true);
        expect(response.body.cardSets.length).toBe(0);
        expect(cardSetRepositoryFind).toHaveBeenCalledTimes(1);
      });
    });

    describe('ORM Integration', () => {
      it('should return DBError', async () => {
        const error = new Error(
          `${ORMErrorNameEnum.AlreadyHasActiveConnectionError}: Some orm error.`
        );
        error.name = ORMErrorNameEnum.AlreadyHasActiveConnectionError;
        /* tslint:disable:no-any */
        const cardSetRepositoryFind = jest
          .spyOn(connection.getRepository('CardSet'), 'find')
          .mockImplementation(async (entity: any): Promise<any> =>
            Promise.reject(error)
          );
        /* tslint:enable:no-any */
//.........这里部分代码省略.........
开发者ID:patrickhousley,项目名称:xyzzy-mean,代码行数:101,代码来源:CardSet.spec.ts


示例9: describe

describe('ImageController', () => {
    let connection: Connection;
    let imageController: ImageController;
    let imageService: ImageService;

    let dummyImage: ImageDto;

    beforeAll(async () => {
        const module = await createTestModule({
            imports: [DtoTransformerModule],
            controllers: [ImageController],
            providers: [
                ImageService,
                FolderService,
                PathHelperService
            ]
        });
        connection = module.get<Connection>(Connection);
        imageController = module.get<ImageController>(ImageController);
        imageService = module.get<ImageService>(ImageService);

        dummyImage = {
            id: 42,
            name: 'dummy',
            extension: 'jpg',
            absolutePath: 'C:\\foo\\bar\\dummy.jpg',
            parentFolder: {
                id: 43,
                name: 'bar',
                absolutePath: 'C:\\foo\\bar'
            } as FolderDto
        };
    });

    beforeEach(async () => {
        await createTestData();
    });

    afterAll(async () => {
        await connection.close();
    });

    describe('create', () => {
        it('should return an image', async () => {
            jest.spyOn(imageService, 'create').mockImplementation(() => dummyImage);
            const result = await imageController.create({ foo: 'bar' });

            expect(result).toBeDefined();
            expect(result).toContainKeys(['id', 'name', 'extension', 'absolutePath']);
        });
    });

    describe('createByPath', () => {
        it('should return an image', async () => {
            jest.spyOn(imageService, 'create').mockImplementation(() => dummyImage);
            const result = await imageController.createByPath({
                absolutePath: 'C:\\foo\\bar\\dummy.jpg',
                name: 'dummy',
                extension: 'jpg'
            });

            expect(result).toBeDefined();
            expect(result).toContainKeys(['id', 'name', 'extension', 'absolutePath']);
        });
    });

    describe('findAll', () => {
        it('should return an array of images', async () => {
            jest.spyOn(imageService, 'findAll').mockImplementation(() => [dummyImage, dummyImage]);
            const result = await imageController.findAll();

            expect(result).toBeDefined();
            expect(result).toBeArrayOfSize(2);
            expect(result[0]).toContainKeys(['id', 'name', 'extension', 'absolutePath']);
            expect(result[1]).toContainKeys(['id', 'name', 'extension', 'absolutePath']);
        });
    });

    describe('findOne', () => {
        it('should return an image', async () => {
            jest.spyOn(imageService, 'findOne').mockImplementation(() => dummyImage);
            const result = await imageController.findOne(42);

            expect(result).toBeDefined();
            expect(result).toContainKeys(['id', 'name', 'extension', 'absolutePath']);
        });
    });

    describe('update', () => {
        it('should return an UpdateResult', async () => {
            jest.spyOn(imageService, 'update').mockImplementation(() => new UpdateResult());
            const result = await imageController.update(42, { foo: 'bar' });

            expect(result).toBeDefined();
            expect(result instanceof UpdateResult).toBeTrue();
        });
    });

    describe('remove', () => {
        it('should return an image', async () => {
//.........这里部分代码省略.........
开发者ID:pschild,项目名称:image-management-tool,代码行数:101,代码来源:image.controller.spec.ts


示例10: describe

describe('FolderService', () => {
    let connection: Connection;
    let folderService: FolderService;
    let imageService: ImageService;

    beforeAll(async () => {
        const module = await createTestModule({
            imports: [DtoTransformerModule],
            providers: [FolderService, PathHelperService, ImageService]
        });
        connection = module.get<Connection>(Connection);
        folderService = module.get<FolderService>(FolderService);
        imageService = module.get<ImageService>(ImageService);
    });

    beforeEach(async () => {
        await createTestData();
    });

    afterAll(async () => {
        await connection.close();
    });

    describe('create', () => {
        it('should save a folder', async () => {
            const f6 = await folderService.findOneByName('F6');
            const result = await folderService.create({
                name: 'dummy-folder',
                parent: f6
            });

            expect(result).toBeDefined();
            expect(result.id).toBeGreaterThan(1);
            expect(result.name).toBe('dummy-folder');
            expect(result.dateAdded).toBeValidDate();
        });
    });

    describe('findOne', () => {
        it('should find folder by id', async () => {
            const result = await folderService.findOne(3, true);

            expect(result).toBeDefined();
            expect(result.id).toBe(3);
            expect(result.name).toBe('F2');
            expect(result.dateAdded).toBeValidDate();
            expect(result.parent.name).toBe('C:');
            expect(result.children).toBeArrayOfSize(1);
            expect(result.children[0].name).toBe('F3');
        });
    });

    describe('findOneByName', () => {
        it('should find folder by name', async () => {
            const result = await folderService.findOneByName('F2', true);

            expect(result).toBeDefined();
            expect(result.id).toBe(3);
            expect(result.name).toBe('F2');
            expect(result.dateAdded).toBeValidDate();
            expect(result.parent.name).toBe('C:');
            expect(result.children).toBeArrayOfSize(1);
            expect(result.children[0].name).toBe('F3');
        });
    });

    describe('findDirectDescendantsByFolderId', () => {
        it('should find direct descendants folders by id', async () => {
            const result = await folderService.findDirectDescendantsByFolderId(1);

            expect(result).toBeDefined();
            expect(result).toBeArrayOfSize(2);
            expect(result.map(folder => folder.name)).toEqual(['F1', 'F2']);
        });
    });

    describe('findDirectDescendantsByFolder', () => {
        it('should find direct descendants folders by folder', async () => {
            const c = await folderService.findOneByName('C:');
            const result = await folderService.findDirectDescendantsByFolder(c);

            expect(result).toBeDefined();
            expect(result).toBeArrayOfSize(2);
            expect(result.map(folder => folder.name)).toEqual(['F1', 'F2']);
        });
    });

    describe('findRootFolders', () => {
        it('should find folders without parent (root folders)', async () => {
            const result = await folderService.findRootFolders();

            expect(result).toBeDefined();
            expect(result).toBeArrayOfSize(2);
            expect(result.map(folder => folder.name)).toEqual(['C:', 'D:']);
        });
    });

    describe('findAll', () => {
        it('should find all folders', async () => {
            const result = await folderService.findAll();
//.........这里部分代码省略.........
开发者ID:pschild,项目名称:image-management-tool,代码行数:101,代码来源:folder.service.spec.ts


示例11: describe

describe('DictionaryEntryResolver', () => {
  let dictionaryEntryResolver: DictionaryEntryResolver;
  let connection: Connection;

  beforeEach(async () => {
    const testModule: TestingModule = await Test.createTestingModule({
      providers: [
        ...databaseProviders,
        ...dictionaryEntryProviders,
        DictinaryEntryService,
        DictionaryEntryResolver,
        AuthGuard,
        {
          provide: Types.CONFIG,
          useValue: {
            mongoConnectionUri: `mongodb://localhost:27017/TEST_${uuidv4()}`,
            secureApiToken: 'test_token',
          },
        },
      ],
    }).compile();

    connection = await prepareDatabaseScenario(testModule, [
      createDataFor<DictionaryEntryEntity>(DictionaryEntryEntity, [
        { japanese: 'inu', english: 'dog' },
        { japanese: 'neko', english: 'cat' },
      ]),
    ]);

    dictionaryEntryResolver = testModule.get<DictionaryEntryResolver>(
      DictionaryEntryResolver,
    );
  });

  afterEach(async () => {
    await connection.dropDatabase();
    await connection.close();
  });

  describe('search', () => {
    it('should return entries containing "dog', async () => {
      const searchResults = await dictionaryEntryResolver.search('dog');
      expect(searchResults).toMatchObject([
        { japanese: 'inu', english: 'dog' },
      ]);
    });
  });

  describe('add entry', () => {
    it('should add new entry', async () => {
      const response = await dictionaryEntryResolver.addDictionaryEntry({
        japanese: 'kame',
        english: 'turtle',
      });

      expect(response).toMatchObject({
        code: 201,
        message: 'Dictionary entry succesfully added.',
        isSuccessful: true,
        dictionaryEntry: {
          japanese: 'kame',
          english: 'turtle',
        },
      });

      const addedEntry = await dictionaryEntryResolver.dictionaryEntry(
        response.dictionaryEntry.id,
      );
      expect(addedEntry).toMatchObject({ japanese: 'kame', english: 'turtle' });
    });
  });
});
开发者ID:vnenkpet,项目名称:japanese,代码行数:72,代码来源:dictionary-entry.resolver.spec.ts


示例12:

 useFactory: (connection: Connection) =>
   connection.getRepository(DictionaryEntryEntity),
开发者ID:vnenkpet,项目名称:japanese,代码行数:2,代码来源:dictionary-entry.providers.ts


示例13: afterEach

 afterEach(async () => {
   await connection.close();
   container.unbind(registry.ORMConnectionOptions);
   container.unbind(registry.ORMConnection);
 });
开发者ID:patrickhousley,项目名称:xyzzy-mean,代码行数:5,代码来源:connection.provider.spec.ts


示例14: describe

describe('FolderController', () => {
    let connection: Connection;
    let folderController: FolderController;
    let folderService: FolderService;

    let dummyFolder: FolderDto;

    beforeAll(async () => {
        const module = await createTestModule({
            imports: [DtoTransformerModule],
            controllers: [FolderController],
            providers: [FolderService, PathHelperService]
        });
        connection = module.get<Connection>(Connection);
        folderController = module.get<FolderController>(FolderController);
        folderService = module.get<FolderService>(FolderService);

        dummyFolder = new FolderDto();
        dummyFolder.id = 43;
        dummyFolder.name = 'bar';
        dummyFolder.absolutePath = 'C:\\foo\\bar';
    });

    beforeEach(async () => {
        await createTestData();
    });

    afterAll(async () => {
        await connection.close();
    });

    describe('create', () => {
        it('should return a folder', async () => {
            jest.spyOn(folderService, 'create').mockImplementation(() => dummyFolder);
            const result = await folderController.create({ foo: 'bar' });

            expect(result).toBeDefined();
            expect(result).toContainKeys(['id', 'name', 'absolutePath']);
        });
    });

    describe('createByPath', () => {
        it('should return a folder', async () => {
            jest.spyOn(folderService, 'createFolderByPath').mockImplementation(() => dummyFolder);
            const result: FolderDto = await folderController.createByPath({ path: 'some/path' });

            expect(result).toBeDefined();
            expect(result).toContainKeys(['id', 'name', 'absolutePath']);
        });
    });

    describe('findAll', () => {
        it('should return an array of folders', async () => {
            jest.spyOn(folderService, 'findAll').mockImplementation(() => [dummyFolder, dummyFolder]);
            const result = await folderController.findAll();

            expect(result).toBeDefined();
            expect(result).toBeArrayOfSize(2);
            expect(result[0]).toContainKeys(['id', 'name', 'absolutePath']);
            expect(result[1]).toContainKeys(['id', 'name', 'absolutePath']);
        });
    });

    describe('findOne', () => {
        it('should return a folder', async () => {
            jest.spyOn(folderService, 'findOne').mockImplementation(() => dummyFolder);
            const result = await folderController.findOne(42);

            expect(result).toBeDefined();
            expect(result).toContainKeys(['id', 'name', 'absolutePath']);
        });
    });

    describe('update', () => {
        it('should return an UpdateResult', async () => {
            jest.spyOn(folderService, 'update').mockImplementation(() => new UpdateResult());
            const result = await folderController.update(42, { foo: 'bar' });

            expect(result).toBeDefined();
            expect(result instanceof UpdateResult).toBeTrue();
        });
    });

    describe('remove', () => {
        it('should return a folder', async () => {
            jest.spyOn(folderService, 'remove').mockImplementation(() => dummyFolder);
            const result = await folderController.remove(42);

            expect(result).toBeUndefined();
        });
    });
});
开发者ID:pschild,项目名称:image-management-tool,代码行数:92,代码来源:folder.controller.spec.ts


示例15: describe

describe('ImageService', () => {
    let connection: Connection;
    let imageService: ImageService;

    beforeAll(async () => {
        const module = await createTestModule({
            imports: [DtoTransformerModule],
            providers: [ImageService]
        });
        connection = module.get<Connection>(Connection);
        imageService = module.get<ImageService>(ImageService);
    });

    beforeEach(async () => {
        await createTestData();
    });

    afterAll(async () => {
        await connection.close();
    });

    describe('create', () => {
        it('should save an image', async () => {
            const result = await imageService.create({
                name: 'dummy-image-99',
                originalName: 'orig-image-99',
                extension: 'png'
            });

            expect(result).toBeDefined();
            expect(result.id).toBeGreaterThan(1);
            expect(result.name).toBe('dummy-image-99');
            expect(result.originalName).toBe('orig-image-99');
            expect(result.extension).toBe('png');
            expect(result.description).toBeNull();
            expect(result.dateAdded).toBeValidDate();
        });
    });

    describe('findOne', () => {
        it('should find image by id', async () => {
            const result = await imageService.findOne(1);

            expect(result).toBeDefined();
            expect(result.id).toBe(1);
            expect(result.name).toBe('dummy-image-1');
            expect(result.originalName).toBe('orig-image-1');
            expect(result.extension).toBe('jpg');
            expect(result.description).toBeNull();
            expect(result.dateAdded).toBeValidDate();
        });
    });

    describe('findAll', () => {
        it('should find all images', async () => {
            const result = await imageService.findAll();

            expect(result).toBeDefined();
            expect(result).toBeArrayOfSize(7);
        });
    });

    describe('findAllByFolderId', () => {
        it('should find all images of folder', async () => {
            const result = await imageService.findAllByFolderId(2); // f1

            expect(result).toBeDefined();
            expect(result).toBeArrayOfSize(2);
            expect(result[0].parentFolder).toBeDefined();
            expect(result[0].parentFolder.name).toBe('F1');
            expect(result.map(image => image.name)).toEqual(['dummy-image-2', 'dummy-image-3']);
        });
    });

    describe('update', () => {
        it('should update an image', async () => {
            const result = await imageService.update(6, {
                name: 'dummy-image-6-new',
                description: 'description-image-6'
            });

            expect(result).toBeDefined();
            expect(result instanceof UpdateResult).toBeTrue();

            const loadedImage = await imageService.findOne(6);
            expect(loadedImage).toBeDefined();
            expect(loadedImage.id).toBe(6);
            expect(loadedImage.name).toBe('dummy-image-6-new');
            expect(loadedImage.originalName).toBe('orig-image-6');
            expect(loadedImage.extension).toBe('jpg');
            expect(loadedImage.description).toBe('description-image-6');
            expect(loadedImage.dateAdded).toBeValidDate();
        });
    });

    describe('remove', () => {
        it('should remove an image', async () => {
            const result = await imageService.remove(6);
            expect(result).toBeDefined();

//.........这里部分代码省略.........
开发者ID:pschild,项目名称:image-management-tool,代码行数:101,代码来源:image.service.spec.ts


示例16: describe

describe('ExplorerController', () => {
    let connection: Connection;
    let explorerController: ExplorerController;
    let explorerService: ExplorerService;
    let folderService: FolderService;
    let fileSystemService: FileSystemService;
    let imageService: ImageService;

    beforeAll(async () => {
        const module = await createTestModule({
            imports: [DtoTransformerModule],
            controllers: [ExplorerController],
            providers: [
                FolderService,
                ExplorerService,
                FileSystemService,
                PathHelperService,
                ImageService
            ]
        });
        connection = module.get<Connection>(Connection);
        explorerController = module.get<ExplorerController>(ExplorerController);
        explorerService = module.get<ExplorerService>(ExplorerService);
        folderService = module.get<FolderService>(FolderService);
        fileSystemService = module.get<FileSystemService>(FileSystemService);
        imageService = module.get<ImageService>(ImageService);

        jest.spyOn(fileSystemService, 'getFilesByPath').mockResolvedValue([{
            name: 'F3',
            absolutePath: 'some/drive/F3',
            isFile: false,
            isDirectory: true
        }, {
            name: 'new folder',
            absolutePath: 'some/drive/new folder',
            isFile: false,
            isDirectory: true
        }, {
            name: 'dummy-image-4',
            absolutePath: 'some/drive/dummy-image-4.jpeg',
            extension: 'jpeg',
            isFile: true,
            isDirectory: false
        }]);
    });

    beforeEach(async () => {
        await createTestData();
    });

    afterAll(async () => {
        await connection.close();
    });

    describe('getContentByFolderId', () => {
        it('should return the same result as getContentByFolderPath', async () => {
            const c = await folderService.findOneByName('C:');

            const mergeResult1 = await explorerController.getContentByFolderPath('C:');
            const mergeResult2 = await explorerController.getContentByFolderId(c.id);
            expect(mergeResult1).toEqual(mergeResult2);
        });
    });

    describe('getContentByFolderPath', () => {
        it('should return a correctly merged result', async () => {
            const f2 = await folderService.findOneByName('F2');
            const f2Path = await folderService.buildPathByFolderId(f2.id);
            const result: IExplorerContentDto | FileSystemException = await explorerController.getContentByFolderPath(f2Path);
            const mergeResult = result as IExplorerContentDto;

            expect(mergeResult.folders).toBeDefined();
            expect(mergeResult.folders).toBeArrayOfSize(2);
            expect(mergeResult.images).toBeDefined();
            expect(mergeResult.images).toBeArrayOfSize(2);

            expect(mergeResult.folders.map(folderDto => folderDto.id)).toEqual([4, undefined]);
            expect(mergeResult.folders.map(folderDto => folderDto.name)).toEqual(['F3', 'new folder']);
            expect(mergeResult.folders.map(folderDto => folderDto.addedInFs)).toEqual([false, true]);
            expect(mergeResult.folders.map(folderDto => folderDto.removedInFs)).toEqual([false, false]);

            expect(mergeResult.images.map(imageDto => imageDto.id)).toEqual([4, 5]);
            expect(mergeResult.images.map(imageDto => imageDto.name)).toEqual(['dummy-image-4', 'dummy-image-5']);
            expect(mergeResult.images.map(imageDto => imageDto.extension)).toEqual(['jpeg', 'TIFF']);
            expect(mergeResult.images.map(imageDto => imageDto.addedInFs)).toEqual([false, false]);
            expect(mergeResult.images.map(imageDto => imageDto.removedInFs)).toEqual([false, true]);
        });
    });

    describe('getSystemDrives', () => {
        it('should return a correctly merged result', async () => {
            jest.spyOn(drivelist, 'list').mockResolvedValue(
                [
                    { mountpoints: [{ path: 'C:\\' }] },
                    { mountpoints: [{ path: 'D:\\' }] }
                ]
            );

            const result: IExplorerContentDto | FileSystemException = await explorerController.getSystemDrives();
            const mergeResult = result as IExplorerContentDto;
//.........这里部分代码省略.........
开发者ID:pschild,项目名称:image-management-tool,代码行数:101,代码来源:explorer.controller.spec.ts


示例17: Close

    public Close(): void {
        if (!this.connection) {
            return;
        }

        this.server.Log('Stopping database...');

        this.connection.close();
        this.connection = undefined;
        this.config = undefined;

        this.server.Log('Database connection closed.');
        this.server = undefined;
    }
开发者ID:Garland220,项目名称:tabletop-audio-player,代码行数:14,代码来源:DatabaseController.ts


示例18: supertest

 it('should respond successfully', async () => {
   /* tslint:disable:no-any */
   const cardSetRepositoryFind = jest
     .spyOn(connection.getRepository('CardSet'), 'find')
     .mockImplementation(async (entity: any): Promise<any> =>
       Promise.resolve([])
     );
   /* tslint:enable:no-any */
   await supertest(app).get('/api/cardSets').expect(200).then(response => {
     expect(response).toBeDefined();
     expect(response.body.cardSets).toBeDefined();
     expect(Array.isArray(response.body.cardSets)).toBe(true);
     expect(response.body.cardSets.length).toBe(0);
     expect(cardSetRepositoryFind).toHaveBeenCalledTimes(1);
   });
 });
开发者ID:patrickhousley,项目名称:xyzzy-mean,代码行数:16,代码来源:CardSet.spec.ts


示例19:

afterAll(async () => {
    conn.close();
});
开发者ID:itaygolan,项目名称:GraphQL-Typescript-Server,代码行数:3,代码来源:createEmailLink.test.ts


示例20: afterEach

 afterEach(async () => {
   await connection.close();
 });
开发者ID:patrickhousley,项目名称:xyzzy-mean,代码行数:3,代码来源:CardSet.spec.ts



注:本文中的typeorm.Connection类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript typeorm.QueryRunner类代码示例发布时间:2022-05-25
下一篇:
TypeScript typeorm.getRepository函数代码示例发布时间:2022-05-25
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap