Skip to content

Commit

Permalink
[fix] CI Warning
Browse files Browse the repository at this point in the history
  • Loading branch information
VecHK committed Dec 26, 2023
1 parent 360e518 commit 8f1beb2
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 16 deletions.
16 changes: 10 additions & 6 deletions server/test/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ module.exports = {

createApp,
getToken,
constructPlainEnvironment,
constructEnvironment,
getHomePagePhotoList,
fetchListWithQQNum,
Expand Down Expand Up @@ -69,12 +70,7 @@ function getToken(app) {
return token;
});
}

async function constructEnvironment({
need_sync = true,
baseNum = 100,
gallery: gallery_init = {},
}) {
async function constructPlainEnvironment(need_sync = true) {
const app = mock.app();
await app.ready();
if (need_sync) {
Expand All @@ -83,6 +79,14 @@ async function constructEnvironment({
});
}
const token = await getToken(app);
return { app, token };
}
async function constructEnvironment({
need_sync = true,
baseNum = 100,
gallery: gallery_init = {},
}) {
const { app, token } = await constructPlainEnvironment(need_sync);

const gallery = await commonCreateGallery(token, app, gallery_init);

Expand Down
19 changes: 9 additions & 10 deletions server/test/image-upload.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,22 @@ const fs = require('fs');
const path = require('path');
const sharp = require('sharp');
const {
createApp,
getToken,
uploadImage,
commonCreateGallery,
createMember,
createPhoto,
test_image_path,
test_image_width,
test_image_height,
constructPlainEnvironment,
} = require('./common');



describe('controller/admin/image', () => {
let app
let token

const pixel_rotated_image_path = `${__dirname}/static/temp.jpg`;
const ori6_image_path = `${__dirname}/static/test-ori-6.jpg`

before(async () => {
app = await createApp()
// // 等待 app 启动成功,才能执行测试用例
token = await getToken(app)

await sharp(test_image_path).rotate(-90).toFile(pixel_rotated_image_path)
// 创建 ori6_image_path 图像,以 pixel_rotated_image_path 为基础添加了 exif 信息
await sharp(pixel_rotated_image_path)
Expand All @@ -38,6 +29,8 @@ describe('controller/admin/image', () => {
})

it('should successfully upload image', async () => {
const { app, token } = await constructPlainEnvironment(true)

const img_meta = await sharp(test_image_path).metadata()
assert(test_image_width, img_meta.width)
assert(test_image_height, img_meta.height)
Expand Down Expand Up @@ -70,6 +63,8 @@ describe('controller/admin/image', () => {
// 第二种方式旋转过的图片,用 sharp 读取的时候不会得到正确的宽度和高度,而是没有改动的位图的宽高
// 这就需要处理了
it('should correctly handle rotated image(rotate by exif Orientation)', async () => {
const { app, token } = await constructPlainEnvironment(true)

const ori6_backdata = await uploadImage(token, app, ori6_image_path)

const member = await createMember(token, app, { qq_num: 22252 })
Expand All @@ -89,6 +84,8 @@ describe('controller/admin/image', () => {
// 这也需要处理
// 因为缩略图需要经过重新压缩,所以直接从第二种旋转方式转为使用第一种旋转方式即可
it('should correctly handle rotated thumb image(rotate by exif Orientation)', async () => {
const { app, token } = await constructPlainEnvironment(true)

const ori6_backdata = await uploadImage(token, app, ori6_image_path)

const down_res = await app.httpRequest()
Expand All @@ -103,6 +100,8 @@ describe('controller/admin/image', () => {
})

it('should successfuly refresh thumb image', async () => {
const { app, token } = await constructPlainEnvironment(true)

const u_img = await uploadImage(token, app, test_image_path)

const thumb_path = app.serviceClasses.image.toThumbSavePath(u_img.src)
Expand Down

0 comments on commit 8f1beb2

Please sign in to comment.