Skip to content

Commit

Permalink
tests pass, not tsc
Browse files Browse the repository at this point in the history
  • Loading branch information
Aaron Shiel committed Nov 11, 2024
1 parent 9e3e6ef commit 30f53e5
Show file tree
Hide file tree
Showing 11 changed files with 36 additions and 31 deletions.
4 changes: 2 additions & 2 deletions cicd/buildspec.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ env:
phases:
install:
runtime-versions:
nodejs: 14
nodejs: 16
commands:
- n 16.18.0 # workaround https://github.com/aws/aws-codebuild-docker-images/issues/490
- n 18.13.0 # workaround https://github.com/aws/aws-codebuild-docker-images/issues/490
- (cd node && NODE_ENV=dev npm ci)

pre_build:
Expand Down
2 changes: 1 addition & 1 deletion cicd/deployspec-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ phases:

pre_build:
commands:
- n 16 # workaround https://github.com/aws/aws-codebuild-docker-images/issues/490
- n 18.13.0 # workaround https://github.com/aws/aws-codebuild-docker-images/issues/490
build:
commands:
- echo Deploying stack
Expand Down
4 changes: 2 additions & 2 deletions cicd/deployspec-prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ env:
phases:
install:
runtime-versions:
nodejs: 14
nodejs: 16

pre_build:
commands:
- n 16 # workaround https://github.com/aws/aws-codebuild-docker-images/issues/490
- n 18.13.0 # workaround https://github.com/aws/aws-codebuild-docker-images/issues/490
# TODO
# - export SENTRY_RELEASE=${SENTRY_PROJECT}-$(cat .VERSION)
build:
Expand Down
4 changes: 2 additions & 2 deletions cicd/deployspec-qa.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ env:
phases:
install:
runtime-versions:
nodejs: 14
nodejs: 16

pre_build:
commands:
- n 16 # workaround https://github.com/aws/aws-codebuild-docker-images/issues/490
- n 18.13.0 # workaround https://github.com/aws/aws-codebuild-docker-images/issues/490
# TODO
# - export SENTRY_RELEASE=${SENTRY_PROJECT}-$(cat .VERSION)
build:
Expand Down
11 changes: 10 additions & 1 deletion node/src/gql/mutation/me/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,16 @@ export function idOrNew(id: string | Types.ObjectId): Types.ObjectId {
}

export function isId(id: string | Types.ObjectId): boolean {
return Boolean(id.toString().match(/^[0-9a-fA-F]{24}$/));
return Boolean(id?.toString().match(/^[0-9a-fA-F]{24}$/));
}

export function validateAndConvertToObjectId(
id: string | Types.ObjectId
): Types.ObjectId {
if (!isId(id)) {
throw new Error('provided id is not a valid object id');
}
return new Types.ObjectId(id);
}

export enum UseDefaultTopics {
Expand Down
1 change: 0 additions & 1 deletion node/src/gql/query/find-by-parent-field.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ export function findByParentFieldQuery<T>(
resolve: async (parent: any) => {
const id = parent[fieldName];
const item = await model.findById(id).exec();
console.log(`${fieldName} item: ${JSON.stringify(item, null, 2)}`);
if (!item) {
throw new Error(`${fieldName} not found for id "${id}"`);
}
Expand Down
13 changes: 10 additions & 3 deletions node/src/gql/types/mentor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import { QuestionType as QuestionGQLType } from './question';
import { TrainStatus } from '../../models/MentorTrainTask';
import { MentorConfigType } from '../../models/MentorConfig';
import { Types } from 'mongoose';
import { validateAndConvertToObjectId } from '../mutation/me/helpers';

export const MentorOrgPermissionType = new GraphQLObjectType({
name: 'MentorOrgPermissionType',
Expand Down Expand Up @@ -167,7 +168,9 @@ export const MentorType = new GraphQLObjectType({
return await MentorModel.getTopics({
mentor: mentor,
defaultSubject: args.useDefaultSubject,
subjectId: args.subject,
subjectId: args.subject
? validateAndConvertToObjectId(args.subject)
: undefined,
});
},
},
Expand All @@ -191,7 +194,9 @@ export const MentorType = new GraphQLObjectType({
return await MentorModel.getQuestions({
mentor: mentor,
defaultSubject: args.useDefaultSubject,
subjectId: args.subject,
subjectId: args.subject
? validateAndConvertToObjectId(args.subject)
: undefined,
topicId: args.topic,
type: args.type as QuestionType,
});
Expand All @@ -217,7 +222,9 @@ export const MentorType = new GraphQLObjectType({
return await MentorModel.getAnswers({
mentor: mentor,
defaultSubject: args.useDefaultSubject,
subjectId: args.subject,
subjectId: args.subject
? validateAndConvertToObjectId(args.subject)
: undefined,
topicId: args.topic,
status: args.status as Status,
});
Expand Down
23 changes: 7 additions & 16 deletions node/src/models/Mentor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import {
MentorImportJson,
ReplacedMentorDataChanges,
} from '../gql/mutation/me/mentor-import';
import { idOrNew, isId } from '../gql/mutation/me/helpers';
import { idOrNew } from '../gql/mutation/me/helpers';
import UserQuestion, { HydratedUserQuestion } from './UserQuestion';
import { QuestionUpdateInput } from '../gql/mutation/me/question-update';
import { Organization } from './Organization';
Expand Down Expand Up @@ -138,7 +138,7 @@ export interface Mentor extends Document<Types.ObjectId> {
export interface GetMentorDataParams {
mentor: string | Mentor;
defaultSubject?: boolean;
subjectId?: string;
subjectId?: Types.ObjectId;
topicId?: string;
type?: QuestionType;
status?: Status;
Expand Down Expand Up @@ -755,14 +755,9 @@ MentorSchema.statics.getSubjects = async function (
// - one subject: sorted in subject order

MentorSchema.statics.getTopics = async function (
{ mentor, defaultSubject, subjectId: _targetSubjectId }: GetMentorDataParams,
{ mentor, defaultSubject, subjectId: targetSubjectId }: GetMentorDataParams,
subjects?: Subject[]
): Promise<Topic[]> {
const targetSubjectIsObjectId = isId(_targetSubjectId);
if (!targetSubjectIsObjectId) {
throw new Error('provided invalid subject id');
}
const targetSubjectId = new Types.ObjectId(_targetSubjectId);
const userMentor: Mentor =
typeof mentor === 'string' ? await this.findById(mentor) : mentor;
if (!userMentor) {
Expand Down Expand Up @@ -850,13 +845,9 @@ MentorSchema.statics.getQuestions = async function ({
if (!userMentor) {
throw new Error(`mentor ${mentor} not found`);
}
const _subjectId = defaultSubject
? userMentor.defaultSubject
: subjectId
? new Types.ObjectId(subjectId)
: undefined;
const subjectIds = _subjectId
? userMentor.subjects.includes(_subjectId)
subjectId = defaultSubject ? userMentor.defaultSubject : subjectId;
const subjectIds = subjectId
? userMentor.subjects.includes(subjectId)
? [subjectId]
: []
: userMentor.subjects;
Expand Down Expand Up @@ -930,7 +921,7 @@ MentorSchema.statics.getAnswers = async function ({
return acc;
}, {});
const answerResult = questionIds.map((qid: Types.ObjectId) => {
const questionDoc = questions.find((q) => qid == q._id);
const questionDoc = questions.find((q) => qid == q._id) || qid;
return (
answersByQid[`${qid}`] || {
mentor: userMentor._id,
Expand Down
2 changes: 1 addition & 1 deletion node/test/graphql/mutation/api/upload-answer.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ describe('uploadAnswer', () => {
const answers = await AnswerModel.find({
mentor: '5ffdf41a1ee2c62111111111',
question: '511111111111111111111112',
})
});

expect(response.status).to.equal(200);
expect(response.body.data.api.uploadAnswer).to.eql(true);
Expand Down
2 changes: 1 addition & 1 deletion node/test/graphql/query/mentor.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -719,7 +719,7 @@ describe('mentor', () => {
});
});

it.only('mentor/answers gets mentor specific question for mentor', async () => {
it('mentor/answers gets mentor specific question for mentor', async () => {
const response = await request(app)
.post('/graphql')
.send({
Expand Down
1 change: 0 additions & 1 deletion node/test/graphql/query/subjects.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,6 @@ describe('subjects', () => {
}
}`,
});
console.log(JSON.stringify(response.body, null, 2));
expect(response.status).to.equal(200);
expect(response.body.data.subjects).to.eql({
edges: [
Expand Down

0 comments on commit 30f53e5

Please sign in to comment.