我在JSON中的第1位收到500个意外的JSON o。
const request = require('supertest');
const app = require('../../../../index');
const httpStatus = require('http-status');
const User = require('../../../models/auth/user.model');
const bcrypt = require('bcryptjs');
const appModel = require('../../../models/app/apps.model');
const RefreshToken = require('../../../models/auth/refreshToken.model');
describe('API', async () => {
let appParam;
let validApiParam;
let userAccessToken;
let Ace;
const password = '123456';
beforeEach(async () => {
const passwordHashed = await bcrypt.hash(password, 1);
Ace = {
email: '[email protected]',
password: passwordHashed,
name: 'ace',
role: 'user',
};
await User.deleteMany({});
await appModel.deleteMany({});
await RefreshToken.deleteMany({});
await User.insertMany([Ace]);
Ace = await User.findOne({ name: Ace.name }).exec();
appParam = {
name: 'aegis project',
appDescription: 'It is authentication app',
userId: Ace._id.toString(),
};
appParam = await appModel.create(appParam);
validApiParam = {
name: 'validNewApi',
url: 'testurl',
methodName: 'POST',
apiType: 2,
requestParameter: {
'email': '[email protected]',
'password': 'cityslicka',
},
responseParameter: {
'version': '1',
'user': {
'id': 123,
},
},
userIdKeyPath: 'user.id',
serviceProvider: 'axios',
userId: Ace._id.toString(),
appId: appParam._id.toString(),
};
Ace.password = password;
userAccessToken = (await User.findAndGenerateToken(Ace)).accessToken;
});
describe('POST /apiRegistration/save-login-api/save-login-api', () => {
it('should create a new login Api', () => {
return request(app)
.post('/apiRegistration/save-login-api/save-login-api')
.set('Authorization', `Bearer ${userAccessToken}`)
.send(JSON.stringify(validApiParam))
.expect(httpStatus.CREATED)
.then(() => {
});
});
});
});
任何建议提供将是有益的。
找到了解决方法,我是在我的逻辑中解析已经JSON格式化的请求参数,导致了这个错误。